What are the default settings for GCC include directories?

When I compile a very simple source file with gcc, I do not need to specify the path to standard include files such as stdio or stdlib.

How does GCC know how to find these files?

Does it have a /usr/include path embedded internally, or will it get paths from other OS components?

+105
c ++ c gcc linux include-path
Feb 12 '11 at 9:45 a.m.
source share
4 answers

To find out the default paths used by gcc / g++ , as well as their priorities, you need to study the output of the following commands:

  1. For C :
  gcc -xc -E -v - 
  1. For C ++ :
  gcc -xc++ -E -v - 

The loan belongs to the Qt Creator team .

+148
Jul 12 2018-11-17T00:
source share

There is a command with a shorter output, which allows you to automatically cut included strokes from lines, starting with one 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. 

Credit goes to lib ++ on the first page .

+30
Nov 07 '13 at 15:34
source share

Here is an article describing gcc search paths: http://www.network-theory.co.uk/docs/gccintro/gccintro_21.html

In addition, you can specify additional search paths using the -I . You can do this from the command line or in your file.

+2
Feb 12 2018-11-12T00:
source share

Just run the following to get a list of default search paths:

$ (gcc -print-prog-name = cc1) -v

0
Jun 18 '19 at 8:17
source share



All Articles