What Are the Gcc Default Include Directories

What are the GCC default include directories?

In order to figure out the default paths used by gcc/g++, as well as their priorities, you need to examine the output of the following commands:

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

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

The credit goes to Qt Creator team.

How do I know the default include directories, default link directories and default link libraries of gcc, g++/c++ in Ubuntu 11.04?

Say gcc -v, or g++ -v to print out verbose information about the environment.

E.g. for me this says:

#include <...> search starts here:
/usr/local/lib/gcc/i686-pc-linux-gnu/4.6.2/../../../../include/c++/4.6.2
/usr/local/lib/gcc/i686-pc-linux-gnu/4.6.2/../../../../include/c++/4.6.2/i686-pc-linux-gnu
/usr/local/lib/gcc/i686-pc-linux-gnu/4.6.2/../../../../include/c++/4.6.2/backward
/usr/local/lib/gcc/i686-pc-linux-gnu/4.6.2/include
/usr/local/include
/usr/local/lib/gcc/i686-pc-linux-gnu/4.6.2/include-fixed
/usr/include

Also try gcc -dumpspecs to see details about the invoked tools in the tool chain.

How to add a default include path for GCC in Linux?

Try setting C_INCLUDE_PATH (for C header files) or CPLUS_INCLUDE_PATH (for C++ header files).

As Ciro mentioned, CPATH will set the path for both C and C++ (and any other language).

More details in GCC's documentation.

Finding out what the GCC include path is

The command

echo | gcc -E -Wp,-v -

will show the include path in use.

Where are include files stored - Ubuntu Linux, GCC

See here: Search Path

Summary:

#include <stdio.h>

When the include file is in brackets the preprocessor first searches in paths specified via the -I flag. Then it searches the standard include paths (see the above link, and use the -v flag to test on your system).

#include "myFile.h"

When the include file is in quotes the preprocessor first searches in the current directory, then paths specified by -iquote, then -I paths, then the standard paths.

-nostdinc can be used to prevent the preprocessor from searching the standard paths at all.

Environment variables can also be used to add search paths.

When compiling if you use the -v flag you can see the search paths used.

Getting the compiler default include path into a makefile

Found the problem... the '#' character in the sed command was causing the issue and cause make to consider everything after as a comment.

For posterity, the fixed command is much easier since the include path start with a ' ':

arm-none-eabi-gcc -xc -E  -Wp,-v  /dev/null 2>&1 | sed -En '/^ /s/^ /-I/p'


Related Topics



Leave a reply



Submit