Directory search sequence for include files using relative path names

C and C++ define two versions of the #include preprocessor directive. IBM(R) XL C/C++ supports both. With the #include directive, the include filename is enclosed between either the < > or " " delimiter characters.

Your choice of delimiter characters will determine the search path used to locate a given include filename. The compiler will search for that include file in all directories in the search path until the include file is found, as follows:

#include type Directory search order
#include <file_name>
  1. The compiler first searches for file_name in each user directory specified by the -Idirectory compiler option, in the order that they appear on the command line.
  2. For C++ compilations, the compiler then searches the standard search path for C++ headers. The default standard search path for C++ headers is /usr/vacpp/include, but this path can be changed with the -qcpp_stdinc compiler option.
  3. Finally, the compiler searches the standard search path for C headers. The default standard search path for C headers is /usr/include.
#include "file_name"
  1. The compiler first searches for the include file in the directory where your current source file resides. The current source file is the file that contains the directive #include "file_name".
  2. The compiler then searches for the include file according to the search order described above for #include <file_name>.
Notes:
  1. file_name specifies the name of the file to be included, and can include a full or partial directory path to that file if you desire.
  2. The only difference between the two versions of the #include directive is that the " " (user include) version first begins a search from the directory where your current source file resides. Typically, standard header files are included using the < > (system include) version, and header files that you create are included using the " " (user include) version.
  3. You can change the search order by specifying the -qstdinc and -qidirfirst options along with the -Idirectory option.

    Use the -qnostdinc option to search only the directories specified with the -Idirectory option and the current source file directory, if applicable. For C programs, the /usr/include directory is not searched. For C++ programs, the /usr/vacpp/include and /usr/include directories are not searched.

    Use the -qidirfirst option with the #include "file_name" directive to search the directories specified with the -Idirectory option before searching other directories.

    Use the -I option to specify the directory search paths.

Related information