[cfe-dev] A bit of help with Clang C++ header search paths

Louis Dionne via cfe-dev cfe-dev at lists.llvm.org
Mon Apr 22 13:21:25 PDT 2019


Here's my understanding of how include paths for the C++ Standard Library work in Clang (this assumes -stdlib=libc++):

1. Based on the platform, the driver looks at various things like the installation path for Clang and passes `-internal-isystem <some-path>/c++/v1` to CC1.
2. The driver also passes -isysroot to CC1 if its own command-line contained -isysroot.
3. CC1 adds the path passed in -internal-isystem as the first search path in the search list.
4. CC1 looks at -isysroot and adds `<SYSROOT>/usr/include/c++/v1` to the header search paths (after whatever was specified in `-internal-isystem`). If no -isysroot was specified, `/` is used (and so `/usr/include/c++/v1` is added).
5. Any path that doesn't exist is removed from the list of search paths.

Is this accurate? If so, I'm wondering why CC1 adds `<SYSROOT>/usr/include/c++/v1` to the search paths in (4) -- it seems like it should rely solely on the `-internal-isystem` path passed to it by the driver? Why isn't that the case?


More information about the cfe-dev mailing list