Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

prevent gcc from searching the current dir "-I-" option on include search path

Our dev environment makes heavy use of directories with locally modified headers that should be seen by the compiler instead of the "committed" "repository" versions.

If header A includes header B, gcc looks for B in the same directory A was in and does not obey the seach path. So we used the -I- option on gcc to prevent that. Gcc will strictly follow the hierarchy of the include-path then. As with gcc4 the -I- option is deprecated and repaced by -iqoute. I can't figure out how to get the same behaviour with the -iquote option because I think it is lacking the side-effect of disabling the search in the "current" directory.

see http://gcc.gnu.org/onlinedocs/cpp/Invocation.html#Invocation

Any ideas how to achieve the same behaviour?

like image 517
John Doe Avatar asked Sep 10 '12 14:09

John Doe


People also ask

Where does GCC search for include files?

GCC looks for headers requested with #include " file " first in the directory containing the current file, then in the directories as specified by -iquote options, then in the same places it would have looked for a header requested with angle brackets. For example, if /usr/include/sys/stat.

What is include path in C?

For include files that are specified as #include "path-spec" , directory search begins in the directory of the parent file and then proceeds through the directories of any grandparent files. That is, the search begins relative to the directory that contains the source file that's being processed.

Where is the header file path?

Most standard headers are stored in /usr/include . It looks like stdbool. h is stored somewhere else, and depends on which compiler you are using. For example, g++ stores it in /usr/include/c++/4.7.


1 Answers

AFAIK, there is no other way to desactivate the behaviour you are complaining about other than using the form #include <foo.h> instead of #include "foo.h" in your code.

ISTR, but I've failed to find a reference, that the rationale for deprecating -I- without providing another mechanism for that aspect is that libraries commonly use the form #include "foo.h" to ensure they get their own internal header file foo.h and the use of -I- broke them in some cases if someone else happened to have a file similarly named earlier on the search path.

like image 79
AProgrammer Avatar answered Sep 19 '22 14:09

AProgrammer