clanglibrary-path

How to specify a custom stdlib directory for LLVM


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?


Solution

  • A combination of -B and --sysroot did the trick for the libraries. A combination of -nostdinc, -isystem and -cxx-isystem did the trick for the includes. Not all these flags are displayed by clang --help, some of them I learned from man gcc, some other reading the Clang source code, and some other online.

    -gcc-toolchain also made a difference, but it was using weird rules to find the libraries, disallowing symlinks in the pathname components etc., so I ended up using the other flags above instead.