clang include multiple search path in the same directory

Viewed 632

According to Clang doc:

-I < directory >
Add the specified directory to the search path for include files.

I wounder if there a way to add multiple search path on the same directory with one -I command, something like this:

-I"Dir1/SubDir/SubDir/SubDir/{IncludePath1,IncludePath2,IncludePath3}"

My project folder tree (unfortunately) is in a formation that there are 2 main folders for include paths which each one includes many paths for the -I option. This cause the clang command to be very long and i will give an example:

clang (...) 
-I"Dir1/SubDir/SubDir/.../SubDir/IncludePath1"
-I"Dir1/SubDir/SubDir/.../SubDir/IncludePath2"
-I"Dir1/SubDir/SubDir/.../SubDir/IncludePath3"
-I"Dir1/SubDir/SubDir/.../SubDir/(And so on...)" 
-I"Dir2/SubDir/SubDir/.../SubDir/IncludePath1"
-I"Dir2/SubDir/SubDir/.../SubDir/IncludePath2"
-I"Dir2/SubDir/SubDir/.../SubDir/IncludePath3"
-I"Dir2/SubDir/SubDir/.../SubDir/(And so on...)" 

So again i wonder if there a way to tell clang to search with one command multiple search path or maybe make it search within a specific dir

1 Answers

Use options -isysroot and -iwithsysroot:

clang -isysroot"Dir1/SubDir/SubDir/SubDir/" -iwithsysroot"/IncludePath1/" \
  -iwithsysroot"/IncludePath2/" -iwithsysroot"/IncludePath3/"

Unfortunately, this solution only works for one main folder and it also makes those include folders system ones, i.e., Clang won't show any warnings for them. Also, -iwithsysroot is pretty long, so you may not save much typing there :) But I'm not aware of any better way to do this directly via Clang options. Although you could always write a shell script to ease the job...


Note. While digging through Clang command line reference trying to find a better solution, I came across option -ivfsoverlay that seems like it maybe could solve your problem. I wasn't able to make it work, though, but I still decided to leave it here, maybe it'll be useful for you.

Related