3

I apt-get-ed the clang and this is what happens when I try to compile simple 2 line program: ( I have g++ on the machine, IDK if that is the cause of the problem)

clang teststring.cpp -v Ubuntu clang version 3.0-6ubuntu3 (tags/RELEASE_30/final) (based on LLVM 3.0) Target: i386-pc-linux-gnu Thread model: posix "/usr/bin/clang" -cc1 -triple i386-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name teststring.cpp -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu pentium4 -target-linker-version 2.22 -momit-leaf-frame-pointer -v -resource-dir /usr/bin/../lib/clang/3.0 -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/include/c++/4.6 -internal-isystem /usr/include/c++/4.6/i686-linux-gnu -internal-isystem /usr/include/c++/4.6/backward -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.0/include -internal-externc-isystem /usr/include/i686-linux-gnu -internal-externc-isystem /usr/include -fdeprecated-macro -ferror-limit 19 -fmessage-length 80 -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-fragile-abi -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/teststring-e3FNx4.o -x c++ teststring.cpp clang -cc1 version 3.0 based upon llvm 3.0 hosted on i386-pc-linux-gnu ignoring nonexistent directory "/usr/include/i686-linux-gnu" ignoring nonexistent directory "/usr/include/c++/4.6//i686-linux-gnu/32" ignoring nonexistent directory "/usr/include/i686-linux-gnu/" ignoring nonexistent directory "/usr/include/i686-linux-gnu" ignoring duplicate directory "/usr/include/c++/4.6" ignoring duplicate directory "/usr/include/c++/4.6/i686-linux-gnu" ignoring duplicate directory "/usr/include/c++/4.6/backward" ignoring duplicate directory "/usr/include/c++/4.6" ignoring duplicate directory "/usr/include/c++/4.6/backward" ignoring duplicate directory "/usr/include/c++/4.6" ignoring duplicate directory "/usr/include/c++/4.6/i686-linux-gnu" ignoring duplicate directory "/usr/include/c++/4.6/backward" ignoring duplicate directory "/usr/local/include" ignoring duplicate directory "/usr/bin/../lib/clang/3.0/include" ignoring duplicate directory "/usr/include" include "..." search starts here: include <...> search starts here: /usr/include/c++/4.6 /usr/include/c++/4.6/i686-linux-gnu /usr/include/c++/4.6/backward
/usr/local/include /usr/bin/../lib/clang/3.0/include /usr/include
/usr/include/i386-linux-gnu/ /usr/include/clang/3.0/include/ /usr/lib/gcc/i686-linux-gnu/4.6/include/
/usr/lib/gcc/i686-linux-gnu/4.6/include-fixed/ End of search list.
"/usr/bin/ld" -z relro --hash-style=gnu --as-needed --build-id --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o a.out /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crti.o /usr/lib/gcc/i686-linux-gnu/4.6/crtbegin.o -L/usr/lib/gcc/i686-linux-gnu/4.6 -L/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu -L/lib/i386-linux-gnu -L/usr/lib/i386-linux-gnu -L/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu -L/usr/lib/gcc/i686-linux-gnu/4.6/../../.. -L/lib/i386-linux-gnu -L/lib -L/usr/lib/i386-linux-gnu -L/usr/lib /tmp/teststring-e3FNx4.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i686-linux-gnu/4.6/crtend.o /usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crtn.o
/tmp/teststring-e3FNx4.o: In function main':
teststring.cpp:(.text+0x18): undefined reference to
std::basic_string, std::allocator

::basic_string()' teststring.cpp:(.text+0x2b): undefined reference to std::string::operator+=(char const*)' teststring.cpp:(.text+0x3e): undefined reference tostd::basic_string, std::allocator >::~basic_string()' teststring.cpp:(.text+0x58): undefined reference to std::basic_string<char, std::char_traits<char>, std::allocator<char> ::~basic_string()' teststring.cpp:(.text+0x79): undefined reference tostd::terminate()' /tmp/teststring-e3FNx4.o:(.eh_frame+0x13): undefined reference to `__gxx_personality_v0' clang: error: linker command failed with exit code 1 (use -v to see invocation)

P.S. for curious program is :

#include <string>
int main()
{
        std::string s;
        s+="banana";
}

1 Answer 1

9

This is C++ code, so try using clang++ instead of clang so that the C++ standard library is linked.

Sign up to request clarification or add additional context in comments.

2 Comments

wow... I cant believe I didnt know this... is this recent... I vaguely remember running clang without ++ on cpp sources.
You can do that if you manually link to the C++ standard library with -lstdc++ (or -lc++ for libc++). It's the same with gcc and g++.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.