I have LLVM 3.3 with Clang, and
$ /tmp/clang/bin/clang -print-search-dirs
programs: =/tmp/clang/bin:/usr/lib/gcc/i486-linux-gnu/4.4/../../../../i486-linux-gnu/bin
libraries: =/tmp/clang/bin/../lib/clang/3.3:/usr/lib/gcc/i486-linux-gnu/4.4:/usr/lib/gcc/i486-linux-gnu/4.4/../../../../lib32:/usr/lib/../lib32:/usr/lib/i486-linux-gnu/../../lib32:/usr/lib/gcc/i486-linux-gnu/4.4/../../..:/lib:/usr/lib
How can I instruct Clang to usage an stdlib (e.g. libgcc
) directory other than /usr/lib/gcc/i486-linux-gnu/4.4
? I'd like to make it use /tmp/mygccstd
instead.
It's also looking in /usr/lib
and /lib
. How do I disable that?
On my system I have 3 compilers installed. gcc-7.3.0, gcc-7.2.0, and clang-6.0
gcc-7.3.0 is installed to the system path and is the system default compiler.
gcc-7.2.0 is installed to /usr/local and is a build requirement for a specific tool.
clang-6.0 is installed to /usr/local and is used for it's stricter warnings/errors.
My boost libraries are compiled with gcc-7.2.0 and I wished to use clang to compile my specific tool. By default, with -stdlib=libstdc++
clang would find gcc-7.3.0 and boost would fail to link.
To get around this I used the following compile flags:
-stdlib=libstdc++ # Tell clang to parse the headers as libstdc++ not libc++
-cxx-isystem /usr/local/include/c++/7.2.0/ # includes for libstdc++
-cxx-isystem /usr/local/include/c++/7.2.0/x86_64-pc-linux-gnu/ # includes for libstdc
And the following linker flags:
-L/usr/local/lib64/ # static libstdc++
-L/usr/local/lib/gcc/x86_64-pc-linux-gnu/7.2.0/ #static libgcc
You can fill in your own linker paths with the directories that hold libstdc++.a
and libgcc.a
and these will depend on where your compiler is installed to.
This is documented in the libcxx docs:
clang++ -std=c++17 -stdlib=libc++ -nostdinc++ \
-I<libcxx-install-prefix>/include/c++/v1 \
-L<libcxx-install-prefix>/lib \
-Wl,-rpath,<libcxx-install-prefix>/lib \
test.cpp
<libcxx-install-prefix>
will be the <location of clang binary>/../../
This stops the compiler from using system dylib.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With