Undefined reference to `__cxa_thread_atexit@@CXXABI` when compiling with `libc++` on linux

巧了我就是萌 提交于 2019-12-09 18:15:22

问题


I'm trying to compile my projects on Arch Linux x64 using libc++, libc++abi and clang++ 3.6.0.

The projects compile properly, but fail to link with the following error:

error: CMakeFiles/main.cpp.o: undefined reference to symbol '__cxa_thread_atexit@@CXXABI_1.3.7'

/usr/lib/libstdc++.so.6:-1: error: error adding symbols: DSO missing from command line

I'm compiling and linking using the -stdlib=libc++ -lc++abi flags.

Is there any additional library I should link? Am I missing a flag?


回答1:


Either link with -lsupc++ or provide a small wrapper function (probably the better way for libc++) for the glibc implementation:

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);
}

It may be worth to mention that this only works with glibc >= 2.18.



来源:https://stackoverflow.com/questions/29322666/undefined-reference-to-cxa-thread-atexitcxxabi-when-compiling-with-libc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!