Specify Path Names for Include Files

When you imbed one source file in another using the #include preprocessor directive, you must supply the name of the file to be included. You can specify a file name either by using a full path name or by using a relative path name.


Directory Search Sequence for Include Files Using Relative Path Names

C and C++ define two versions of the #include preprocessor directive. IBM 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 directories specified by the -qcpp_stdinc and -qgcc_cpp_stdinc compiler options.
  3. Finally, the compiler then searches the directories specified by the -qc_stdinc and -qgcc_c_stdinc compiler options.

#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.

    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 References

I
c_stdinc
cpp_stdinc
gcc_c_stdinc
gcc_cpp_stdinc
idirfirst
stdinc IBM Copyright 2003