/I (Search Directory for Include Files)

Option

/Idirectory

You can add to the list of directories searched for include files by using the /I (for “include”) option. The space between /I and directory is optional.

The search process for included files can involve three stages and begins with the #include directive. If the file specified to the #include directive contains a complete drive and path specification, that file is included without searching any directories. If the specified file is enclosed in double quotation marks, the directory of the file containing the #include directive is searched. If the current file is also an include file, the directory of the parent file is searched until the original source file's directory is searched.

The second stage uses the /I option. If the file is still not found or if it is specified to the #include directive in angle brackets, a directory specified by an /I command-line option is searched. To search more than one directory, give additional /I options on the CL command line—one /I option for each directory. Use a space to separate multiple /I options. Multiple directories are searched in order of their appearance on the command line. The directories are searched only until the specified include file is found.

The third and final stage involves the INCLUDE environment varible. If the file is not found in a directory specified by an /I option, a directory or path specified in the INCLUDE environment variable is used. This enables you to give a particular file special handling without changing the compiler environment you usually use. If the include file is not found, the compiler prints an error message and stops processing. When this occurs, you must restart compilation with a corrected directory specification.

Examples

CL /I \INCLUDE /I\MY\INCLUDE MAIN.C

In this example, CL looks for the include files requested by MAIN.C in the following order: first in the directory \INCLUDE, then in the directory \MY\INCLUDE, and finally in the directory or directories assigned to the INCLUDE environment variable.

CL /X /I \ALT\INCLUDE MAIN.C

In this example, the compiler looks for include files only in the directory \ALT\INCLUDE. The /X option, described later in this chapter, tells CL to consider the list of standard places empty; then the /I option specifies one directory to be searched.