Directory search sequence for include files

The XL C/C++ compiler supports the following types of include files:
  • Header files supplied by the compiler (referred to throughout this document as XL C/C++ headers)
  • Header files mandated by the C and C++ standards (referred to throughout this document as system headers)
  • Header files supplied by the operating system (also referred to throughout this document as system headers)
  • User-defined header files
You can use any of the following methods to include any type of header file:
  • Use the standard #include <file_name> preprocessor directive in the including source file.
  • Use the standard #include "file_name" preprocessor directive in the including source file.
  • Use the -include compiler option.

If you specify the header file using a full (absolute) path name, you can use these methods interchangeably, regardless of the type of header file you want to include. However, if you specify the header file using a relative path name, the compiler uses a different directory search order for locating the file depending on the method used to include the file.

Furthermore, the -qstdinc compiler option can affect this search order. The following summarizes the search order used by the compiler to locate header files depending on the mechanism used to include the files and on the compiler options that are in effect:
  1. Header files included with -include only: The compiler searches the current (working) directory from which the compiler is invoked.
  2. Header files included with -include or #include "file_name": The compiler searches the directory in which the souce file is located.
  3. All header files: The compiler searches each directory specified by the -I compiler option, in the order that it displays on the command line.
  4. All header files: The compiler searches the standard directory for the system headers. The default directory for these headers is specified in the compiler configuration file. This location is set during installation, but the search path can be changed with the -isystem (-qgcc_c_stdinc or -qgcc_cpp_stdinc) option.1
Note:
  1. If the -nostdinc or -nostdinc++ (-qnostdinc) compiler option is in effect, step 4 is omitted.


Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us