我在我的Ubuntu 13.04机器上安装了clang 3.2,并编译和构建了libc ++,一切都已就绪。 但是,当我尝试链接我的(非常简单的)代码时,链接器报告对std :: cout等的引用是未定义的。
如果有人可以告诉我我能做些什么来解决这个问题,我会非常感激 - 我已经尝试了我能想到的一切。
命令和输出在这里:
$ clang++ -v -stdlib=libc++ -lpthread -ldl sqlite3/sqlite3.o src/world.o -o bin/world
Ubuntu clang version 3.2-1~exp9ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2)
Target: x86_64-pc-linux-gnu
Thread model: posix
"/usr/bin/ld" -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o bin/world /usr/bin/../lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o /usr/bin/../lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crti.o /usr/bin/../lib/gcc/x86_64-linux-gnu/4.7/crtbegin.o -L/usr/bin/../lib/gcc/x86_64-linux-gnu/4.7 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/bin/../lib/gcc/x86_64-linux-gnu/4.7/../../.. -L/lib -L/usr/lib -lpthread -ldl sqlite3/sqlite3.o src/world.o -lc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/bin/../lib/gcc/x86_64-linux-gnu/4.7/crtend.o /usr/bin/../lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crtn.o
src/world.o: In function `main':
/home/douglivesey/work/home/cpp/clang/biots/src/world.cpp:17: undefined reference to `std::cout'
/home/douglivesey/work/home/cpp/clang/biots/src/world.cpp:17: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/home/douglivesey/work/home/cpp/clang/biots/src/world.cpp:17: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/home/douglivesey/work/home/cpp/clang/biots/src/world.cpp:17: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
src/world.o: In function `__cxx_global_var_init':
/usr/include/c++/4.7.3/iostream:74: undefined reference to `std::ios_base::Init::Init()'
/usr/include/c++/4.7.3/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [bin/world] Error 1
答案 0 :(得分:4)
错误显示来自GCC libstdc ++的标题和符号,表示world.o
是使用-stdlib=libstdc++
构建的,但您链接的-stdlib=libc++
不兼容。
您需要始终使用相同的-stdlib
选项。