Search code examples
c++includeinclude-path

where are all the places C++ searches for includes?


Is there a way to check all of the locations C++ searches for includes? I would like to understand why some includes are found and others are not.

EDIT: Platform is Linux, g++


Solution

  • This is compiler-dependent: you pass the locations for the headers in angular brackets, and the headers in double quotes are expected to be at the path rooted at the location of the current file; compilers also let you specify additional locations for these files.

    For example, gcc has two options - -I and -i for specifying locations of headers specified as <header.h> and "header.h". If -I is not specified, the default locations of

     /usr/local/include
     libdir/gcc/target/version/include
     /usr/target/include
     /usr/include
    

    are searched, as specified in the gcc documentation.