[cfe-dev] Extracting the include tree from a source file

Bertjan Broeksema broeksema at kde.org
Thu Nov 18 11:21:50 PST 2010


Nico Weber wrote:

> Hm, this _might_ be because clang comes with a few standard headers,
> see clang/lib/Headers. Maybe clang adds these to the search path
> somehow. Adding a gentoo-specific include path is the correct fix in
> this case.

Yes it is because clang needs this standard headers installed in 
/usr/lib/clang/2.8/include (on linux of course, don't know about other 
platforms). From libs/Driver/Driver.cpp: (line 76 and further in 2.8)

// Compute the path to the resource directory.
llvm::sys::Path P(Dir);
P.eraseComponent(); // Remove /bin from foo/bin
P.appendComponent("lib");
P.appendComponent("clang");
P.appendComponent(CLANG_VERSION_STRING);
ResourceDir = P.str();


I don't really understand why. Moreover, I don't understand why 
AddGnuCPlusPlusIncludePaths in InitHeaderSearch.cpp is implemented as is. 
For example take:

AddGnuCPlusPlusIncludePaths(
         "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.4/include/g++-v4",
         "x86_64-pc-linux-gnu", "32", "", triple);

The directory above (i.e. /usr/lib/gcc/x86_64-pc-linux-gnu/4.4.3/include/) 
also contains the headers which are in /usr/lib/clang/2.8/include. So I 
wondered why AddGnuCPlusPlusIncludePaths, doesn't add this path too so that 
the clang include directory is not required.

This might be Gentoo specific, meaning that for other distros the current 
code *does* find the standard headers and therefore doesn't need the clang 
include path. If so, please tell me. In that case for the Gentoo adding a 
line like:

AddPath( "/usr/lib/gcc/x86_64-pc-linux-gnu/4.4.4/include/"
         , System, true, false, false );

would remove the need for custom apps to add the clang include dir.

Cheers,

Bertjan




More information about the cfe-dev mailing list