C++ 使用 Libc++ 未定义引用使用 Clang 进行编译
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7016730/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Compiling with Clang using Libc++ undefined references
提问by norcalli
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.
第一对太长,无法参考。当我尝试clang++ -stdlib=libc++ ../main.cc ...
使用 SVN 中的 clang 和 libc++进行编译时,出现此错误。
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.
解决方案:感谢其中一个答案,我知道了解决方案。libc++不能像 libstdc++ 那样单独使用,它必须与libc++abi一起链接。不过,libc++abi 还没有完成,所以使用 libc++ 暂时似乎有点不完整,但它完成后仍然是我的第一选择。
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
.
2012 年 5 月 26 日更新:C++ 的 libc++abi 现已完成,我已成功使用 clang++ 如下clang++ -std=c++11 -stdlib=libc++ -lc++abi
。
采纳答案by Arvid
I believe libc++ doesn't support all exception functions yet. See the status page:
我相信 libc++ 还不支持所有异常函数。查看状态页面:
http://libcxxabi.llvm.org/spec.html
http://libcxxabi.llvm.org/spec.html
You could probably link against gnu's libstdc++
您可能可以链接到 gnu 的 libstdc++
回答by Vir
Here's what works for me with the Ubuntu Vivid packages for clang and libc++:
以下是适用于 clang 和 libc++ 的 Ubuntu Vivid 软件包的内容:
clang++ -std=c++11 -stdlib=libc++ <object files> -lc++abi -lsupc++
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.
重要的是目标文件出现在-l
标志之前,例如当您使用异常时。显然,如果您使用针对 libstdc++ 编译的库并在这些接口中使用任何 STL 类型,这仍然不会链接。
回答by Tobias Schlegel
This seems like you are using exception handling, but it isn't enabled in the compiler. Try passing -fexceptions to the commandline.
这似乎您正在使用异常处理,但在编译器中未启用。尝试将 -fexceptions 传递给命令行。