【发布时间】:2024-10-22 20:40:01
【问题描述】:
我正在尝试使用 clang++-4.0 编译我的第一个 C++ 胚胎
我的代码:
//main.cpp
#include <iostream>
// this line is to deal with the link error:
// "undefined reference to symbol '__cxa_thread_atexit@@CXXABI..."
// cf. http://*.com/q/29322666/356440
extern "C" int __cxa_thread_atexit(void (*func)(), void *obj,
void *dso_symbol) {
int __cxa_thread_atexit_impl(void (*)(), void *, void *);
return __cxa_thread_atexit_impl(func, obj, dso_symbol);
}
int main ()
{
return 0;
}
我使用clang++-4.0 编译,并以这种方式与ld 链接:
clang++-4.0 -c main.cpp -o main.o
ld -o test main.o -lc++ -lc++abi -lc
好像我缺少与另一个库的链接,但我不知道是哪一个。
你看到有什么问题或遗漏了吗?我想我在 linux 上用clang++ 做 c++ 东西时缺少一些初学者的东西。
编译错误:
ld:警告:找不到入口符号_start;默认为 0000000000400380 main.o: 在函数
__cxx_global_var_init': main.cpp:(.text.startup+0x13): undefined reference tostd::ios_base::Init::Init()' main.cpp:(.text.startup+0x19): 未定义 参考std::ios_base::Init::~Init()' main.cpp:(.text.startup+0x2d): undefined reference to__dso_handle' //usr/lib/x86_64-linux-gnu/libc++.so: 未定义的引用_Unwind_GetRegionStart' //usr/lib/x86_64-linux-gnu/libc++.so: undefined reference to_Unwind_RaiseException' //usr/lib/x86_64-linux-gnu/libc++.so: 未定义的引用_Unwind_SetIP' //usr/lib/x86_64-linux-gnu/libc++.so: undefined reference to_Unwind_GetLanguageSpecificData' //usr/lib/x86_64-linux-gnu/libc++.so: 未定义的引用_Unwind_Resume' //usr/lib/x86_64-linux-gnu/libc++.so: undefined reference to_Unwind_GetIP' //usr/lib/x86_64-linux-gnu/libc++.so: 对_Unwind_SetGR' //usr/lib/x86_64-linux-gnu/libc++.so: undefined reference to_Unwind_DeleteException'的未定义引用
【问题讨论】:
-
@πάνταῥεῖ 我不认为这是重复的。这里未定义的引用没有链接到我的代码。在这里,我尝试编译一个只返回 0 的主函数......没有别的......
-
这就是为什么我没有欺骗你的问题。
-
在命令行的末尾添加
-lcpp会发生什么?这是通过包管理器安装的clang版本,还是您从源代码构建的? -
通过包管理器安装,并将 apt.llvm.org 添加到我的 apt 源列表中。当我添加链接
-lcpp时,ld抱怨它不知道。