gccclangcompiler-flagsgnu-toolchain

CC -I vs -isystem command line argument differences and specific behavior


I have seen this question already.
Many compilers and compiler toolchains support the -I <dir> and -isystem <dir> command line arguments. I do know that they add directories to the search path and system search path respectively and that system directories get searched last and that -isystem helps you override default system libraries.
I also know that they get special treatment by GCC 'to fix buggy system headers' but what specifically does GCC do in this 'special treatment'?
Also, It is unclear to me if the compiler only looks in the specified directory and no deeper, or if these directories are searched recursively to some extent.

If I need to access resources in /path/to/lib and path/to/lib/aBitFurther do I only need -I /path/to/lib?


Solution

  • The main differences is that GCC suppresses warnings in system headers. In some cases, this enables those headers to use certain non-standard GNU extensions.

    The treatment for buggy system headers you mention is an overlay directory tree with header files preprocessed using the fixincludes tool, but that's not something you'll see on GNU/Linux systems because it is extremely messy and causes lots of problems (such as hiding subsequent updates of the official system headers). I hope it's of historic interest only by this point (although GCC still prepares these headers during its build process).