Clang includes search path


I’m trying to set the includes search path in clang, but I can’t figure out how to do it?

I’m working on OSX and every time I compile a C/C++ code, I have to specify it with -isysroot (and I don’t want an alias, or a symlink to /usr/include) since the includes are not in a really standard path on OSX (e.g.: /Applications/

Is there a way to do that?


I think the libc++ folks recommend building libc++ along with clang. If you do that, the c++ includes files will get copied under the relative include path and will be found automatically. However, you’ll need to set DYLD_LIBRARY_PATH in order to pick up the correct, just built, libc++ library.

But if you really do want to use the installed version of libc++, you can use xcrun to dynamically find the path via xcrun and set CPLUS_INCLUDE_PATH.

$ export CPLUS_INCLUDE_PATH=$(dirname $(xcrun -f clang))/…/include/c++/v1


I saw the CPLUS_INCLUDE_PATH variable in the code but wasn’t sure how to use it. I’ll try that.