Why doesn't the linker find std::cout and other std entries? - eclipse-cdt

I am trying to compile a simple program using clang++ under Eclipse CDT Kepler under Fedora. Below is a clang++ compilation log run within Eclipse.
If I enter at the command prompt 'clang++ ../src/Hello\ LLVM\ and\ Clang.cc' I get no errors. If I enter the Eclipse commands I do duplicate the linkage error messages.
Various SOs and the clang mailing list said that undefined references to std::??? are caused by using clang instead of clang++ as well as use libc++ instead of libstdc++. In the 3rd and 4th line, clang++ is used. In the 4th line, stdc++.
I am using the LLVM with Clang (Linux) Eclipse defined Tool Chain.
Interesting behavior is when I select Properties->C/C++ Build->Tool Chain Editor, I see LLVM with Clang (Linux) as the tool chain. If I select Linux GCC. When I go back to select from the list of Tool Chains, the LLMV with Clang (Linux) is gone! It would seem that the tool is not 'supported' but it seems to be supported. Curious.
What do I do to get clang++ to build under Eclipse CDT Kepler? The path to the libraries seems to be the key to the problem.
21:43:42 **** Rebuild of configuration Debug for project Hello LLVM and Clang ****
Info: Internal Builder is used for build
clang++ -O0 -emit-llvm -g3 -Wall -c -fmessage-length=0 -o "src/Hello LLVM and Clang.bc" "../src/Hello LLVM and Clang.cc"
clang++ -v -L/usr/lib -L/usr/i686-w64-mingw32/sys-root/mingw/lib/ -o "Hello LLVM and Clang" "src/Hello LLVM and Clang.bc" -lstdc++
clang version 3.3 (tags/RELEASE_33/final)
Target: i386-redhat-linux-gnu
Thread model: posix
"/usr/bin/clang" -cc1 -triple i386-redhat-linux-gnu -emit-obj -mrelax-all -disable-free - disable-llvm-verifier -main-file-name "Hello LLVM and Clang.bc" -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu pentium4 -target-linker-version 2.23.2 -v -resource-dir /usr/bin/../lib/clang/3.3 -fdebug-compilation-dir "/home/ksmith/C++PlayProjects/Hello LLVM and Clang/Debug" -ferror-limit 19 -fmessage-length 0 -mstackrealign -fobjc-runtime=gcc -fobjc-default-synthesize-properties -fdiagnostics-show-option -backend-option -vectorize-loops -o "/tmp/Hello LLVM and Clang-mT5CWp.o" -x ir "src/Hello LLVM and Clang.bc"
clang -cc1 version 3.3 based upon LLVM 3.3 default target i386-redhat-linux-gnu
"/usr/bin/ld" --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o "Hello LLVM and Clang" /usr/lib/gcc/i686-redhat-linux/4.8.2/../../../crt1.o /usr/lib/gcc/i686-redhat-linux/4.8.2/../../../crti.o /usr/lib/gcc/i686-redhat-linux/4.8.2/crtbegin.o -L/usr/lib -L/usr/i686-w64-mingw32/sys-root/mingw/lib/ -L/usr/lib/gcc/i686-redhat-linux/4.8.2 -L/usr/lib/gcc/i686-redhat-linux/4.8.2/../../.. -L/lib -L/usr/lib "/tmp/Hello LLVM and Clang-mT5CWp.o" -lstdc++ -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/i686-redhat-linux/4.8.2/crtend.o /usr/lib/gcc/i686-redhat-linux/4.8.2/../../../crtn.o
/tmp/Hello LLVM and Clang-mT5CWp.o: In function `main':
/home/ksmith/C++PlayProjects/Hello LLVM and Clang/Debug/../src/Hello LLVM and Clang.cc:12: undefined reference to `std::cout'
/home/ksmith/C++PlayProjects/Hello LLVM and Clang/Debug/../src/Hello LLVM and Clang.cc:13: 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/ksmith/C++PlayProjects/Hello LLVM and Clang/Debug/../src/Hello LLVM and Clang.cc:13: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/home/ksmith/C++PlayProjects/Hello LLVM and Clang/Debug/../src/Hello LLVM and Clang.cc:13: undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
/tmp/Hello LLVM and Clang-mT5CWp.o: In function `__cxx_global_var_init':
/usr/lib/gcc/i686-redhat-linux/4.8.2/../../../../include/c++/4.8.2/iostream:74: undefined reference to `std::ios_base::Init::Init()'
/usr/lib/gcc/i686-redhat-linux/4.8.2/../../../../include/c++/4.8.2/iostream:74: undefined reference to `std::ios_base::Init::~Init()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
21:43:44 Build Finished (took 1s.982ms)

Related

Ubuntu Clang linker error: undefined reference to symbol '__gxx_personality_v0

I wanted to try and use clang instead of gcc on my Ubuntu system. I set up the most basic C++ project possible, with a minimal CMakeLists.txt:
cmake_minimum_required(VERSION 3.20)
project(pcb_engine)
add_executable(main main.cpp)
My main.cpp is also very simple:
#include <iostream>
int main() {
std::cout << "Hello World" << std::endl;
return 0;
}
No when I run g++ -o main_g++ ../main.cpp everything compiles just fine. Also, if I set my system's default compiler to be gcc and g++ using
sudo update-alternatives --config c++
sudo update-alternatives --config cc
and I run cmake .. and make from my build folder, everything works!
The error:
Now I switch to using clang and clang++ as my default compiler via the update-alternatives command and while the build file generation succeeds, the make command fails with the following error message:
fatal error: 'iostream' file not found
#include <iostream>
When I run clang++ -v -stdlib=libc++ -Wall ../main.cpp -o main_clang manually, I get a linker error:
Ubuntu clang version 14.0.0-1ubuntu1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;#m64
Selected multilib: .;#m64
"/usr/lib/llvm-14/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debugger-tuning=gdb -v -fcoverage-compilation-dir=/home/ivan/Documents/TEST/build -resource-dir /usr/lib/llvm-14/lib/clang/14.0.0 -internal-isystem /usr/lib/llvm-14/bin/../include/c++/v1 -internal-isystem /usr/lib/llvm-14/lib/clang/14.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wall -fdeprecated-macro -fdebug-compilation-dir=/home/ivan/Documents/TEST/build -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/main-482542.o -x c++ ../main.cpp
clang -cc1 version 14.0.0 based upon LLVM 14.0.0 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/llvm-14/bin/../include/c++/v1
/usr/lib/llvm-14/lib/clang/14.0.0/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
"/usr/bin/ld" -pie -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o main_clang /lib/x86_64-linux-gnu/Scrt1.o /lib/x86_64-linux-gnu/crti.o /usr/bin/../lib/gcc/x86_64-linux-gnu/12/crtbeginS.o -L/usr/bin/../lib/gcc/x86_64-linux-gnu/12 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/usr/lib/llvm-14/bin/../lib -L/lib -L/usr/lib /tmp/main-482542.o -lc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/bin/../lib/gcc/x86_64-linux-gnu/12/crtendS.o /lib/x86_64-linux-gnu/crtn.o
/usr/bin/ld: /tmp/main-482542.o: undefined reference to symbol '__gxx_personality_v0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libc++abi.so.1: error adding symbols: DSO missing from command line
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The non-verbose error message:
/usr/bin/ld: /tmp/main-f39fec.o: undefined reference to symbol '__gxx_personality_v0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libc++abi.so.1: error adding symbols: DSO missing from command line
Can anyone help me identify where to start fixing this?
Interestingly, when I run clang++ -v -stdlib=libstdc++ -Wall ../main.cpp -o main_clang (note the -stdlib=libstdc++ flag change to the gnu standard library), then I get the same simple fatal error: 'iostream' file not found error as with cmake! So there is a difference in the behavior with the two different standard c++ libraries...
The background:
I come from using gcc, and installed clang via get-apt install clang. I've read that clang does not come with its own standard C++ library, but I have trouble understanding the implications for me: Previously, I had issues with clang finding a correct standard library .so file... I tried some more installs and I have got the libstdc++.so (default gnu) and the libc++.so as well as libc++.a and libc++.abi.so in my /usr/lib/x86_64-linux-gnu folder with a correct symlink hierarchy. For some reason, after a system restart, the /usr/bin/ld: cannot find -lstdc++ error went away, and now I have this linker error where it seems that clang can not find the include header files when running cmake. Now, I am at the end of my limited wisdom.

LLVM Kaleidoscope tutorial JIT compilation problem

I have some problems following the Kaleidoscope JIT chapter tutorial.
I compile with: (just like the tutorial page advises)
clang++ -g toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core mcjit native` -rdynamic -O3 -o toy
/tmp/toy-ce525d.o: In function `llvm::orc::LegacyIRCompileLayer<llvm::orc::LegacyRTDyldObjectLinkingLayer, llvm::orc::SimpleCompiler>::addModule(unsigned long, std::unique_ptr<llvm::Module, std::default_delete<llvm::Module> >)':
/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h:93: undefined reference to `llvm::orc::SimpleCompiler::operator()(llvm::Module&)'
/tmp/toy-ce525d.o: In function `llvm::orc::LegacyRTDyldObjectLinkingLayer::ConcreteLinkedObject<std::shared_ptr<llvm::RuntimeDyld::MemoryManager> >::finalize()':
/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h:237: undefined reference to `llvm::orc::JITSymbolResolverAdapter::JITSymbolResolverAdapter(llvm::orc::ExecutionSession&, llvm::orc::SymbolResolver&, llvm::orc::MaterializationResponsibility*)'
/tmp/toy-ce525d.o: In function `llvm::orc::JITSymbolResolverAdapter::~JITSymbolResolverAdapter()':
/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Legacy.h:93: undefined reference to `vtable for llvm::orc::JITSymbolResolverAdapter'
/tmp/toy-ce525d.o: In function `KaleidoscopeJIT':
/home/user/Desktop/llvm/kaleidoscope/other/././KaleidoscopeJIT.h:45: undefined reference to `llvm::orc::ExecutionSession::ExecutionSession(std::shared_ptr<llvm::orc::SymbolStringPool>)'
/tmp/toy-ce525d.o: In function `llvm::DenseSet<llvm::orc::SymbolStringPtr, llvm::DenseMapInfo<llvm::DenseSet> > llvm::orc::lookupWithLegacyFn<llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT()::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)#1}>(llvm::orc::ExecutionSession&, llvm::orc::AsynchronousSymbolQuery&, llvm::DenseMapInfo<llvm::DenseSet> const&, llvm::orc::KaleidoscopeJIT::KaleidoscopeJIT()::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)#1})':
/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Legacy.h:159: undefined reference to `llvm::orc::ExecutionSession::legacyFailQuery(llvm::orc::AsynchronousSymbolQuery&, llvm::Error)'
/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Legacy.h:151: undefined reference to `llvm::orc::AsynchronousSymbolQuery::notifySymbolMetRequiredState(llvm::orc::SymbolStringPtr const&, llvm::JITEvaluatedSymbol)'
/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Legacy.h:155: undefined reference to `llvm::orc::ExecutionSession::legacyFailQuery(llvm::orc::AsynchronousSymbolQuery&, llvm::Error)'
/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/Legacy.h:166: undefined reference to `llvm::orc::AsynchronousSymbolQuery::handleComplete()'
/tmp/toy-ce525d.o:(.rodata._ZTVN4llvm3orc22LegacyLookupFnResolverIZNS0_15KaleidoscopeJITC1EvEUlRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE_EE[_ZTVN4llvm3orc22LegacyLookupFnResolverIZNS0_15KaleidoscopeJITC1EvEUlRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEE_EE]+0x30): undefined reference to `llvm::orc::SymbolResolver::anchor()'
LLVM project in version 10, clang++ in version 6.
$ uname -srmpo
Linux 4.15.0-72-generic x86_64 x86_64 GNU/Linux
$ clang++ --version
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ llvm-config --version
10.0.0git
PradeepKumar fixed the issue in the comment.
This command compiles the code:
clang++ -g toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core mcjit native orcjit` -rdynamic -O3 -o toy
For those who are using the cmake build instructions I just had to add orcjit to llvm_map_components_to_libnames:
llvm_map_components_to_libnames(llvm_libs orcjit support core irreader)

wxwidget wxRichTextCtrl compiled results in ld: symbol(s) not found

I am on MacOS Mojave 10.14. I can compile wxWidget code and have compiled a few demos, etc. The only feature of wxWidget I cannot compile is a wxRichTextCtrl. Whenever I do the following in my main.cpp file I get error:
wxRichTextCtrl* richTextCtrl = new wxRichTextCtrl(this, -1, wxT(""), wxDefaultPosition,
wxSize(250, 150), wxTE_MULTILINE);
I get this error
Undefined symbols for architecture x86_64:
"wxRichTextCtrl::wxRichTextCtrl(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxValidator const&, wxString const&)", referenced from:
MyFrame::MyFrame(wxString const&, wxPoint const&, wxSize const&) in main-498ba7.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have tried replacing "this" with a wxPanel, but that results in the same error. The full error report from g++ is:
Apple clang version 11.0.0 (clang-1100.0.33.5)
Target: x86_64-apple-darwin18.7.0
Thread model: posix
InstalledDir: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin /clang" -cc1 -triple x86_64-apple-macosx10.14.0 -Wdeprecated-objc-isa-usage -Werror=deprecated- objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp- elim -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -ggnu-pubnames -target-linker-version 512.4 -v -resource-dir /Applications /Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0 -I/usr/local/lib/wx/include/osx_cocoa-unicode-static-3.1 -I /usr/local/include/wx-3.1 -D _FILE_OFFSET_BITS=64 -D __WXMAC__ -D __WXOSX__ -D __WXOSX_COCOA__ -stdlib=libc++ -internal-isystem /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1 -Wno-framework-include-private-from-public -Wno-atimport-in-framework- header -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -fdeprecated-macro -fdebug- compilation-dir /Users/user/Downloads/wxWidgets-3.1.3/build/osx -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.14.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/f3/lvdll7257lq_4_fcysmprc700000gn/T/main-b50747.o -x c++ main.cpp
clang -cc1 version 11.0.0 (clang-1100.0.33.5) default target x86_64-apple-darwin18.7.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/lib/wx/include/osx_cocoa-unicode-static-3.1
/usr/local/include/wx-3.1
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin /../include/c++/v1
/usr/local/include
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib /clang/11.0.0/include
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.14.0 -o out -L/usr/local/lib -framework IOKit -framework Carbon -framework Cocoa -framework AudioToolbox -framework System -framework OpenGL /usr/local/lib/libwx_osx_cocoau_xrc-3.1.a /usr/local/lib/libwx_osx_cocoau_qa-3.1.a /usr/local/lib/libwx_baseu_net-3.1.a /usr/local/lib/libwx_osx_cocoau_html-3.1.a /usr/local/lib/libwx_osx_cocoau_core-3.1.a /usr/local/lib/libwx_baseu_xml-3.1.a /usr/local/lib/libwx_baseu-3.1.a -framework WebKit -lwxregexu-3.1 -lwxscintilla-3.1 -lexpat -lpng -ljpeg -ltiff -lz -framework Security -lpthread -liconv -llzma /var/folders/f3/lvdll7257lq_4_fcysmprc700000gn/T/main-b50747.o -lc++ -lSystem /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"wxRichTextCtrl::wxRichTextCtrl(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxValidator const&, wxString const&)", referenced from:
MyFrame::MyFrame(wxString const&, wxPoint const&, wxSize const&) in main-b50747.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I compile from my terminal using g++ and get my linker options, etc from wx-config --cxxflags and wx-config --libs. I program in xCode. Using gcc instead of g++ results in the same error.
By default, wx-config --libs returns only the "standard" libraries (which basically were all the existing libraries back when this was implemented) and not all the available libraries to make it possible to add more libraries later without changing anything for the applications that don't need them.
So if you need to use a library not included in this "standard subset", you must specify it explicitly, like this: wx-config --libs std,richtext.

clang appears not to be linking to a library

I boiled down the problem to the following example:
int main()
{
try {
throw false;
} catch (bool x)
{
if (x)
{
return 0;
}
else
{
return 1;
}
}
}
generates the following errors on Coliru:
/tmp/main-c8b47a.o: In function `main':
main.cpp:(.text+0xf): undefined reference to `typeinfo for bool'
/tmp/main-c8b47a.o: In function `GCC_except_table0':
main.cpp:(.gcc_except_table+0x30): undefined reference to `typeinfo for bool'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Cmd line:
clang++ -std=c++11 -stdlib=libc++ -O2 -Wall -pedantic -pthread main.cpp && ./a.out
This sounds like it's not linking to a library. Does anyone know which and what the command line switches would be? I've not used clang before. This works under g++.
This is the output with the -v switch:
clang version 3.6.0 (tags/RELEASE_360/final 235480)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.6.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.7.3
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.2
Found candidate GCC installation: /usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.2
Found candidate GCC installation: /usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0
Found candidate GCC installation: /usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.2
Found candidate GCC installation: /usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.1.0
Found candidate GCC installation: /usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.2.0
Selected GCC installation: /usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.2.0
Candidate multilib: .;#m64
Selected multilib: .;#m64
"/usr/local/bin/clang" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -disable-llvm-verifier -main-file-name main.cpp -mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -target-linker-version 2.22 -momit-leaf-frame-pointer -v -dwarf-column-info -resource-dir /usr/local/bin/../lib/clang/3.6.0 -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/include -internal-isystem /usr/local/bin/../lib/clang/3.6.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wall -pedantic -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /tmp/1441759762.34715 -ferror-limit 19 -fmessage-length 0 -pthread -mstackrealign -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-loops -vectorize-slp -o /tmp/main-47c098.o -x c++ main.cpp
clang -cc1 version 3.6.0 based upon LLVM 3.6.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/v1
/usr/local/include
/usr/local/bin/../lib/clang/3.6.0/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
"/usr/bin/ld" --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o /usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.2.0/crtbegin.o -L/usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.2.0 -L/usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.2.0/../../../../lib64 -L/usr/local/bin/../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.2.0/../../.. -L/usr/local/bin/../lib -L/lib -L/usr/lib /tmp/main-47c098.o -lc++ -lm -lgcc_s -lgcc -lpthread -lc -lgcc_s -lgcc /usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/5.2.0/crtend.o /usr/lib/x86_64-linux-gnu/crtn.o
/tmp/main-47c098.o: In function `main':
main.cpp:(.text+0xf): undefined reference to `typeinfo for bool'
/tmp/main-47c098.o: In function `GCC_except_table0':
main.cpp:(.gcc_except_table+0x30): undefined reference to `typeinfo for bool'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
It looks like you need to add -lsupc++ after main.cpp (see it live):
clang++ -std=c++11 -stdlib=libc++ -O2 -Wall -pedantic -pthread main.cpp -lsupc++
^^^^^^^^
As Andre Kostur notes the libc++ documentation recommends the following, although I can not seem to get this to work on Coliru:
Unfortunately you can't simply run clang with "-stdlib=libc++" at this
point, as clang is set up to link for libc++ linked to libsupc++. To
get around this you'll have to set up your linker yourself (or patch
clang). For example,
clang++ -stdlib=libc++ helloworld.cpp -nodefaultlibs -lc++ -lcxxrt -lm -lc -lgcc_s -lgcc
Alternately, you could just add libcxxrt to your libraries list, which
in most situations will give the same result:
clang++ -stdlib=libc++ helloworld.cpp -lcxxrt
This looks related to issues being discussed in this thread Making libc++ on Linux user-friendly, with selective quotes below:
Here's the problem: when building libc++, the linker finds the various
ABI functions in libstdc++, and is quite happy with them being there.
When Clang calls the linker for the actual program, though, it doesn't
pass along a link flag for libstdc++, only for libc++. Thus, the links
fails.
and:
This again can be worked around by explicitly specifying linking against the source library, and here -lsupc++ works.
Also see Linux equivalent of Windows DLL forwarders or MacOS reexport_library.

clang-2.9 crt1 not found error

Just compiled clang-2.9 release and it can't link an hello world example. There is the error:
crt1.o: No such file: No such file or directory
LLVM is configured as default + --enable-shared. The llvm-2.8 build with same options works normally on the same machine.
$ clang -v a.c
clang version 2.9 (tags/RELEASE_29/final)
Target: i386-pc-linux-gnu
Thread model: posix
"/root/bin/clang" -cc1 -triple i386-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name a.c -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu pentium4 -target-linker-version 2.18 -momit-leaf-frame-pointer -v -resource-dir /root/lib/clang/2.9 -ferror-limit 19 -fmessage-length 157 -fgnu-runtime -fdiagnostics-show-option -fcolor-diagnostics -o /tmp/cc-2ueoYy.o -x c a.c
clang -cc1 version 2.9 based upon llvm 2.9 hosted on i386-pc-linux-gnu
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
/root/lib/clang/2.9/include
/usr/include
End of search list.
a.c:1:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
main(){}
^~~~
1 warning generated.
"/usr/bin/ld" --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o a.out crt1.o crti.o crtbegin.o -L -L/../../.. /tmp/cc-2ueoYy.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed crtend.o crtn.o
/usr/bin/ld: crt1.o: No such file: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The same error was here http://permalink.gmane.org/gmane.comp.compilers.clang.devel/12101
and http://comments.gmane.org/gmane.comp.compilers.clang.devel/14269 and http://permalink.gmane.org/gmane.comp.compilers.llvm.bugs/11352
What I can learn while comparing with llvm-2.8 -- newer version tries to assemble file itself, and older version calls gcc to do assemble and link steps.
Please, this is not a duplicate of clang linker problem as I can't edit sources of LLVM, so the accepted solution isn't useful to me.
As suggested at http://permalink.gmane.org/gmane.comp.compilers.llvm.bugs/11352 (llvm bug 8897) this is because
gcc used to build clang is not in a standard location
or
system gcc is not listed in the ToolChains.cpp GccVersions list:
./tools/clang/lib/Driver/ToolChains.cpp: const char* GccVersions[] = {"4.5.2", "4.5.1", "4.5", "4.4.5", "4.4.4",
./tools/clang/lib/Driver/ToolChains.cpp- "4.4.3", "4.4", "4.3.4", "4.3.3", "4.3.2",
./tools/clang/lib/Driver/ToolChains.cpp- "4.3", "4.2.4", "4.2.3", "4.2.2", "4.2.1",
./tools/clang/lib/Driver/ToolChains.cpp- "4.2"};
Both cases are true for my installation.
To fix this, I'll try to add my version of gcc into list GccVersions[].
This helps me.