使用 Libc++ 使用 Clang 进行编译未定义的引用

发布于 2024-11-28 20:06:38 字数 1230 浏览 3 评论 0原文

第一对太长,无法参考。当我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

影子的影子 2024-12-05 20:06:38

我相信 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++

鹿港巷口少年归 2024-12-05 20:06:38

以下是适用于 clang 和 libc++ 的 Ubuntu Vivid 软件包的工作原理:

clang++ -std=c++11 -stdlib=libc++ <object files> -lc++abi -lsupc++

重要的是,目标文件位于 -l 标志之前,例如,当您使用异常时。显然,如果您使用针对 libstdc++ 编译的库并在这些接口中使用任何 STL 类型,这仍然不会链接。

Here's what works for me with the Ubuntu Vivid packages for clang and libc++:

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.

靑春怀旧 2024-12-05 20:06:38

这看起来像是您正在使用异常处理,但编译器中未启用它。尝试将 -fExceptions 传递到命令行。

This seems like you are using exception handling, but it isn't enabled in the compiler. Try passing -fexceptions to the commandline.

来日方长 2024-12-05 20:06:38

我只是添加这个答案,因为我刚才确实犯了这个错误。它编译了我几天来写的大部分内容,但现在它开始抛出未定义的引用错误...

所以...我...有点可能是用 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 not clang++. Yeah. That was all that was wrong. clang++ includes C++ library stuff, clang doesn't. Oops!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文