The foremost problem is why the linker cannot find libc++
:
If you want to link a dynamic library, say, libfoo.so
, with the -l
flag,
you use the option -lfoo
, not -llibfoo
. Therefore to link libc++
you use the option -lc++
, not -llibc++
, as you have done. In your
project's libraries (-l) settings, replace libc++
with c++
.
A secondary problem is that the Eclipse-CDT-generated link command:
clang++ -L/usr/lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.8/ -o
C++Test src/C++Test.bc -llibc++ -lstdc++
is attempting to link libstdc++
(the GCC Standard C++ library) as well as
(what is supposed to be) libc++
(the LLVM Standard C++ library). You want to
link one or the other, not both:
You say that even if you delete stdc++
from the project's libraries, it
is automatically added by the Eclipse build. I cannot reproduce that problem.
Perhaps you can double check it:
Delete
stdc++
from the project's libraries and apply that change.Then look at the linker settings -> All options and see if
-lstdc++
appears there. It shouldn't.If it does, look at linker settings -> Miscellaneous -> Linker flags and Other options. Does
-lstdc++
appear there? If so, delete it.Otherwise, look at the linker's Expert settings: commandline pattern. If it contains
-lstdc++
, delete it.
You say also that you have appended the options -std=c++11 -stdlib=libc++
to the compiler Command setting, but this seems to be ignored. They may be
appear to be ignored because only the link step of your project is failing, so
the compile step is not rerun when you build. However it is misguided to
add these options to the compile command:-
-std=c++11
is a compile option. You should add it to compiler -> Miscellaneous -> Other flags.-stdlib=libc++
is a linkage option and, if wanted, should be added to linker -> Miscellaneous -> Linker flags. However it is superfluous to use this option if you also link with-lc++
(and do not link-lstdc++
), and-lc++
is the more dependable option. I suggest you do not bother with-stdlib=libc++
.
In view of your difficulties linking with libc++
one should ask: Do you
really need to? The fact that you are building with clang does not oblige you
to link libc++
. Clang will quite happily link libstdc++
.