9

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?

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah,yes, the -i* explanations on that page are exhaustive.
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.

Comments

1

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

Comments