TAGS :Viewed: 13 - Published at: a few seconds ago

[ Adding a path to the end of gcc search path ]

I can see that adding a path to the gcc search path can be done by using the -I flag. However, when using -v I can see that the path is being searched first.

Is there anyway I can have the search path I added, searched at the very end?

Answer 1


The -idirafter option allows you to specify an include directory for consideration only after all regular -I directories and the standard system directories. This is documented here:

https://gcc.gnu.org/onlinedocs/cpp/Invocation.html#Invocation

-idirafter dir

Search dir for header files, but do it after all directories specified with -I and the standard system directories have been exhausted. dir is treated as a system include directory. If dir begins with =, then the = will be replaced by the sysroot prefix; see --sysroot and -isysroot.

Answer 2


There is an explanation here on SO: Manipulating the search path for include files and also here which may help you.

All three methods from above are mentioned in the linked SO post.

Answer 3


Use the -idirafter option to add a directory to the end of the include search path.