问题
I've built and installed (under the prefix ~/alt
) LLVM-Clang trunk (23 apr 2012) successfully using GCC-4.6 on Ubuntu 12.04 and in turn libc++ using this Clang-build. When I want to use it I have to supply both -lc++
and -libstdc++
as follows
/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
to compile f.cpp
containing
#include <iostream>
using std::cout;
using std::endl;
int main(int argc, const char * argv[]) {
cout << "sxx" << endl;
return 0;
}
If I omit -lstdc++
I get the link error
/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
Shouldn't libc++
be a full replacement for libstdc++
?
回答1:
libcxx doesn't come with the ABI layer... that's why libcxxabi exists.
In theory you should be able to link to libcxxabi.
In practice you might want to link to libsupc++ or libcxxrt
There's some discussion recently on the newsgroup, I'm afraid the solutions is complicated and in flux: http://thread.gmane.org/gmane.comp.compilers.clang.devel/19782
来源:https://stackoverflow.com/questions/10297291/clang-3-1-libc-compile-error