system search path for option -stdlib=libc++


I would like to compile and install llvm/clang/libcxx into a local directory on Linux (Gentoo). I haven’t found the right combination of cmake -D flags to make the -stdlib=c++ option work.

The first part seems straightforward enough:

I wonder if it’d useful for Clang to be able to process multiple sysroots, to handle this kind of situation where some stuff (libc++, llvm, maybe more) are installed to /some/prefix/, but the user still wants to search /usr/ for headers and libs. Today I believe we just require the user to pass lots of -isystem and -L args.

That sounds a lot like Apple’s framework concept.

In case it helps, I'm maintaining a helper script that builds/installs
a standalone llvm/clang/libc++ combo into a prefix of your choice.
--stdlib=libc++ will "just work" with that.

The script got updated to 3.4 recently:

The script patches the code a bit to get around search path problems,
though I'm actually not sure if all the patches are still needed. It
works on Linux and Darwin.


Thanks for the pointer, and for having put this script onto github.

One question. It puts the shared form of libc++ into /lib but clang++ still isn’t being built to look in /lib. Your script is adding a -L argument for this path to the third stage build so clang++ can build clang with the library. Your ‘testit’ script then goes ahead and fails for me because it does not use the -L/lib argument. Does this work for you on a Linux system? If so, I wonder what is different for mine. Or maybe you only tried the testit script on Darwin?

I’ll take another look at those diffs. I didn’t see any that tried to add /lib to the search path, but maybe I overlooked something.



That script and those patches worked great on my Linux/Gentoo system.

The problem I had at first was caused by ‘git am’ failing - my own fault. Once I fixed that, it worked just as you wrote. clang++ pulls in the libc++ library with no -L fuss. That is a very useful script. And clang is built with libc++ in the third stage - nice.

Thanks again.