Clang 3.1 + libc++编译错误

3

我已经成功地使用GCC-4.6在Ubuntu 12.04上构建并安装了LLVM-Clang trunk(2012年4月23日版本),并使用此Clang-build构建了libc++(库)。当我想要使用它时,我必须按照以下方式提供-lc++-libstdc++

预设安装路径为~/alt

/home/per/alt/bin/clang -x c++ -I/home/per/alt/include/v1 -L/home/per/alt/lib -std=gnu++0x -g -Wall ~/f.cpp -lm -lc++ -lstdc++ -lpthread -o f

编译包含f.cpp的代码

#include <iostream>

using std::cout;
using std::endl;

int main(int argc, const char * argv[]) {
    cout << "sxx" << endl;
    return 0;
}

如果省略-lstdc++,将会出现链接错误。
/home/per/alt/include/v1/ostream:989: error: undefined reference to '__cxa_begin_catch'
/home/per/alt/include/v1/ostream:993: error: undefined reference to '__cxa_end_catch'
/home/per/alt/include/v1/ostream:993: error: undefined reference to '__cxa_end_catch'
/tmp/f-4l9mgl.o(.eh_frame+0xd3): error: undefined reference to '__gxx_personality_v0'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Compilation exited abnormally with code 1 at Tue Apr 24 13:59:22

为什么libc++不能完全替代libstdc++


2
main 的签名不正确,我很惊讶它被接受了。 - Matthieu M.
1
Nordlöw,你的CPU架构是什么?是ARM吗?libc++在ARM上没有实现一些__cxa*:http://libcxxabi.llvm.org/spec.html - osgx
1个回答

7

libcxx没有自带ABI层...这就是为什么需要存在libcxxabi。

理论上你应该能够链接到libcxxabi。

但实际上,你可能想链接到libsupc++或libcxxrt。

最近在新闻组里有一些讨论,恐怕解决方案比较复杂而且不稳定: http://thread.gmane.org/gmane.comp.compilers.clang.devel/19782


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接