使用 Libc++ 使用 Clang 进行编译未定义的引用
第一对太长,无法参考。当我尝试使用 SVN 中的 clang 和 libc++ 编译 clang++ -stdlib=libc++ ../main.cc ...
时,出现此错误。
error: undefined reference to 'typeinfo for char const*'
error: undefined reference to '__cxa_allocate_exception'
error: undefined reference to '__cxa_throw'
/tmp/cc-pbn00y.o:../main.cc:function std::__1::deque<double, std::__1::allocator<double> >::__add_back_capacity(): error: undefined reference to '__cxa_begin_catch'
/tmp/cc-pbn00y.o:../main.cc:function std::__1::deque<double, std::__1::allocator<double> >::__add_back_capacity(): error: undefined reference to '__cxa_rethrow'
/tmp/cc-pbn00y.o:../main.cc:function std::__1::deque<double, std::__1::allocator<double> >::__add_back_capacity(): error: undefined reference to '__cxa_end_catch'
/tmp/cc-pbn00y.o(.eh_frame+0xbd3): error: undefined reference to '__gxx_personality_v0'
解决方案:感谢其中一个答案,我知道了解决方案。 libc++ 不能像 libstdc++ 那样单独使用,它必须与 libc++abi 一起链接。然而libc++abi还没有完成,所以使用libc++目前看来还有些不完整,但完成后它仍然是我的第一选择。
更新 5/26/2012: libc++abi 现已完成 C++,我已经成功使用 clang++,如下所示 clang++ -std=c++11 -stdlib=libc++ -lc+ +abi
。
The first couple are too long to reference. I get this error when I try to compile clang++ -stdlib=libc++ ../main.cc ...
with clang and libc++ from the SVN.
error: undefined reference to 'typeinfo for char const*'
error: undefined reference to '__cxa_allocate_exception'
error: undefined reference to '__cxa_throw'
/tmp/cc-pbn00y.o:../main.cc:function std::__1::deque<double, std::__1::allocator<double> >::__add_back_capacity(): error: undefined reference to '__cxa_begin_catch'
/tmp/cc-pbn00y.o:../main.cc:function std::__1::deque<double, std::__1::allocator<double> >::__add_back_capacity(): error: undefined reference to '__cxa_rethrow'
/tmp/cc-pbn00y.o:../main.cc:function std::__1::deque<double, std::__1::allocator<double> >::__add_back_capacity(): error: undefined reference to '__cxa_end_catch'
/tmp/cc-pbn00y.o(.eh_frame+0xbd3): error: undefined reference to '__gxx_personality_v0'
SOLUTION: Thanks to one of the answers, I know the solution. libc++ can't be used by itself like libstdc++, it has to be linked along with libc++abi. However, libc++abi isn't complete yet, so using libc++ seems to be a little incomplete for the moment, but it is still my first choice when it completes.
UPDATE 5/26/2012: libc++abi is now complete for C++ and I have been using clang++ as follows successfully clang++ -std=c++11 -stdlib=libc++ -lc++abi
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我相信 libc++ 还不支持所有异常函数。请参阅状态页面:
http://libcxxabi.llvm.org/spec.html
您可能可以链接到 gnu 的 libstdc++
I believe libc++ doesn't support all exception functions yet. See the status page:
http://libcxxabi.llvm.org/spec.html
You could probably link against gnu's libstdc++
以下是适用于 clang 和 libc++ 的 Ubuntu Vivid 软件包的工作原理:
重要的是,目标文件位于
-l
标志之前,例如,当您使用异常时。显然,如果您使用针对 libstdc++ 编译的库并在这些接口中使用任何 STL 类型,这仍然不会链接。Here's what works for me with the Ubuntu Vivid packages for clang and libc++:
It is important that the object files come before the
-l
flags, e.g. when you use exceptions. Obviously, this still will not link if you use libraries compiled against libstdc++ and use any STL types in those interfaces.这看起来像是您正在使用异常处理,但编译器中未启用它。尝试将 -fExceptions 传递到命令行。
This seems like you are using exception handling, but it isn't enabled in the compiler. Try passing -fexceptions to the commandline.
我只是添加这个答案,因为我刚才确实犯了这个错误。它编译了我几天来写的大部分内容,但现在它开始抛出未定义的引用错误...
所以...我...有点可能是用
clang
而不是进行编译铿锵++。是的。这就是全部错误所在。
clang++
包含 C++ 库内容,而clang
不包含。哎呀!I'm only adding this answer as I literally made this mistake just now. It was compiling most of what I was writing just fine for days, but now it starts throwing undefined reference errors...
So... I... sorta possibly was compiling with
clang
notclang++
. Yeah. That was all that was wrong.clang++
includes C++ library stuff,clang
doesn't. Oops!