Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clang++ 3.2 linker not finding C++ stdlib

I've installed clang 3.2 on my Ubuntu 13.04 machine, and have compiled and built libc++, and everything is in place. However, when I try to link my (really simple) code, the linker reports that references to std::cout etc. are undefined.

If anyone could advise me what I could do to solve this, I'd be very grateful -- I've tried everything I can think of.

The commands and output are here:

$ 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
like image 935
biot023 Avatar asked May 27 '13 10:05

biot023


1 Answers

The errors show headers and symbols from GCC's libstdc++ indicating world.o was built with -stdlib=libstdc++ but you're linking with -stdlib=libc++ which is incompatible.

You need to use the same -stdlib option consistently.

like image 54
Jonathan Wakely Avatar answered Nov 10 '22 06:11

Jonathan Wakely