What are the gcc system include paths?

The #include preprocessor directive in c++ is one of the first things that people learn. They come in two varieties:

  1. #include<> – usually meant for system-level includes such as iostream or other headers from libraries installed at the system level.
  2. #include " " – usually meant for files included from a location relative to the code being written… for instance, another header file for a class you just wrote.

But, where are system level headers stored?  On Linux with the gcc tool chain installed, you can execute the following command to find out:

g++ -E -x c++ - -v < /dev/null

  • -E – Stop after the pre-processing step
  • -x c++ – language of interest is c++
  • -v – verbose output

In the output, look for the section that starts with #include <...> search starts here.  A collection of paths is listed after this line which is where the pre-processor will look for any includes that are in <...> (angle brackets).

FWIW, there’s also a way to include additional paths to be used as system includes on the command line when compiling code.

Speak Your Mind

*

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.