include Search Paths

The include preprocessor directive allows you to retrieve source statements from secondary input files and incorporate them into your program.

There are two ways you can control the disk directories searched by the compiler when it looks for include files.

Path Fully Qualified
When the compiler encounters either a user or system include file directive with a fully qualified file name (full path and filename), it looks only in the directory specified by the name.

Path Not Fully Qualified (User include Files)
When the compiler encounters a user include file specification that is not fully qualified, it searches for the file in the following places, in order:

  1. The directory of the original top-level file.
  2. Any directories specified using /I that have not been removed with /Xc. Directories specified in the ICC environment variable are searched before those specified on the command line.
  3. Any directories listed in the INCLUDE environment variable, unless you specified the /Xi option.

Path Not Fully Qualified (System include Files)
When the compiler encounters a system include file specification that is not fully qualified, it searches for the file in the following places, in order:

  1. Any directories specified using /I that have not been removed with /Xc. Directories specified in the ICC environment variable are searched before those specified in the command line.
  2. Any directories listed in the INCLUDE environment variable, unless you specified the /Xi option.

Accumulation of Options
The include search options are cumulative between the  ICC  and INCLUDE environment variables and the command line. For example, given the following  ICC  and INCLUDE environment variables:

   ICC=/I\roseanne

   INCLUDE=c:\kent;\alan

and the following command line:

   icc /Xi+ /Ic:\connie test.c /Xi- /Xc /Id:\dal f:\moe\marko\jay.c

The include files are processed as follows:

User include files
Any user include files referenced in test.c are searched for first in the current directory, then in the directory \rosanne, and then in c:\connie. Because of the /Xi- option, none of the directories in INCLUDE are searched.

Any user include files referenced in jay.c are searched for in the following directories, in the given order: f:\moe\marko, d:\dal, c:\kent, and \alan. The directories in INCLUDE are searched because the /Xi- option overrides the /Xi+ option specified previously. The /Xc option removes the directories \roseanne and c:\connie from the current search path.

System include files
Any system include files referenced in the file test.c are searched for first in the directory \roseanne and then in the directory c:\connie. Because of the /Xi+ option, none of the directories in INCLUDE are searched.

Any system include files referenced in the file f:\moe\marko\jay.c will be searched for first in the d:\dal directory, then in the c:\kent directory, and finally the \alan directory. The directories in INCLUDE are searched because the /Xi- option overrides the /Xi+ option specified previously. The /Xc option removes the directories \roseanne and c:\connie from the current search path.



include Files


Environment Variables for Compiling