错误libc++.so:未定义对"_Unwind_GetRegionStart"的引用

Error libc++.so: undefined reference to `_Unwind_GetRegionStart'

本文关键字:Unwind 引用 GetRegionStart libc++ so 未定义 错误      更新时间:2023-10-16

我正在尝试用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://stackoverflow.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 to std::ios_base::Init::Init()' main.cpp:(.text.startup+0x19): undefined 参考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的未定义引用

不应将C++应用程序与ld链接。与C++编译器可执行文件的链接,因为它链接到所有必要的库中:

clang++-4.0 -c main.cpp -o main.o
clang++-4.0 -o test main.o