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.
- Use a Full Path Name to Imbed Files
The full path name, also called the absolute path name, is the
file's complete name starting from the root directory. These path names start with the /
(slash) character. The full path name locates the specified file regardless of the
directory you are presently in (called your working or current directory).
The following example specifies the full path to file mine.h in John Doe's
subdirectory example_prog:
/u/johndoe/example_prog/mine.h
- Use a Relative Path Name to Imbed Files
The relative path name locates a file relative to the directory that holds the
current source file or relative to directories defined using the -Idirectory option.
See AIX Version 4 System User's Guide: Operating System and Devices for a
complete explanation of the AIX. file system.
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> |
- 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.
- For C++ compilations, the compiler searches the directory /usr/vacpp/include.
- The compiler searches the directory /usr/include.
|
#include "file_name" |
- Searches the directory where your current source file resides. The current source file
is the one that contains the directive #include "file_name".
- 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.
- For C++ compilations, the compiler searches the directory /usr/vacpp/include.
- The compiler searches the directory /usr/include.
|
Notes:
- 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.
- 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.
- 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.