When i compile a very simple source file with gcc I don’t have to specify the path to standard include files such as stdio or stdlib.
How GCC knows how to find these files?
Does it have the
/usr/include path hardwired inside, or it will get the paths from other OS components?
In order to figure out the default paths used by gcc/g++ as well as their priorities you examine the output of the following commands:
gcc -xc -E -v -
gcc -xc++ -E -v -
The credit goes to Qt Creator team.
There is a command with a shorter output, which allows to automatically cut the include pathes from lines, starting with a single space:
$ echo | gcc -Wp,-v -x c++ - -fsyntax-only ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.8.2/include-fixed" ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../x86_64-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2 /usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/x86_64-redhat-linux /usr/lib/gcc/x86_64-redhat-linux/4.8.2/../../../../include/c++/4.8.2/backward /usr/lib/gcc/x86_64-redhat-linux/4.8.2/include /usr/local/include /usr/include End of search list.
The credit goes to the libc++ front-page.
Here is an article describing the gcc search paths: http://www.network-theory.co.uk/docs/gccintro/gccintro_21.html
In addition, you can specify extra search paths with the
-I switch. You can do this from the command line or in your makefile.