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.

The following example specifies the full path to file mine.h in John Doe's subdirectory example_prog:

/u/johndoe/example_prog/mine.h

Directory Search Sequence for Include Files Using Relative Path Names

The C and C++ languages defines two versions of the #include preprocessor directive. IBM VisualAge C++ supports both. With the #include directive, you can search directories by enclosing the file name between < > or " " characters.

The result of using each method is as follows:

#include type

Directory Search Order

#include <file_name>

  1. If you specify the -Idirectory option, the compiler searches for file_name in the directory called directory first. If more than one directory is specified, the compiler searches the directories in the order that they appear on the command line.
  2. For C++ compilations, the compiler searches the directory /usr/vacpp/include.
  3. The compiler searches the directory /usr/include.

#include "file_name"

  1. Searches the directory where your current source file resides. The current source file is the one that contains the directive #include "file_name".
  2. If you specify the option -Idirectory, the compiler searches for file_name in directory. If more than one directory is specified, the compiler searches the directories in the order that they appear on the command line.
  3. For C++ compilations, the compiler searches the directory /usr/vacpp/include.
  4. The compiler searches the directory /usr/include.

Notes:

  1. file_name is the path name of the file to be included. When you specify a full path name, the two versions of the #include directive have the same effect because the location of the file to be included is completely specified. With a relative path name, the directory search sequence is determined by whether you use the < > or the " " characters.
  2. The only difference between the two versions of the #include directive is that the " " (user include) version first searches in 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.