Microsoft KB Archive/38383

{| = INFO: Include Directories Not Searched as Expected =
 * width="100%"|

Article ID: Q38383

The information in this article applies to:
 * The Microsoft C/C++ Compiler (CL.EXE) included with: - Microsoft C for MS-DOS, versions 6.0, 6.0a, 6.0ax - Microsoft C for OS/2, versions 6.0, 6.0a - Microsoft C/C++ for MS-DOS, version 7.0 - Microsoft Visual C++ for Windows, versions 1.0, 1.5 - Microsoft Visual C++ 32-bit Edition, versions 1.0, 2.0, 4.0, 5.0

SUMMARY
It may appear that the C compiler searches the INCLUDE list in the wrong order. While the search order for a file enclosed in brackets (<>) is simple, the order for a file enclosed in double quotation marks (&quot;&quot;) is different and more complicated.

MORE INFORMATION
NOTE: Using double quotation marks around a complete path specification causes the standard directories to NOT be searched.

As documented in the &quot;Include Files&quot; section of the Visual C++, 16-bit edition, &quot;Microsoft C Language Reference,&quot; and &quot;The #include Directive&quot; section of the Visual C++, 32-bit edition, &quot;Preprocessor Reference,&quot; the search order for a statement like &quot;#include &quot; is as follows:

1. Any directories specified using the /I switch on the CL command

line, from left to right. 2. Directories specified in the include environment variable, again from left to right. 3. If the file is not found in either of these steps, the following error is issued:

fatal error C1015: cannot open include file 'file.h'

The Microsoft C/C++ compiler included with Visual C++, 32-bit edition, will issue the following error:

fatal error C1083: Cannot open include file: 'file.h': No such file or directory For the following example, only the &quot;\path&quot; directory on the current default drive is searched: #include &quot;\path\file.h&quot; The standard directories are not searched. However, the search order for #include &quot;file.h&quot; is similar to the search order for #include  except that &quot;parent directories&quot; are searched before directories specified by the /I switch and before directories specified in the INCLUDE environment variable. The parent directory is the directory that contains the source containing the #include directive. If #include files are nested, then the parent directories are searched in reverse order of the nesting: first parents, then grandparents, and so on.

For example, if source file GRANDMA.C contains

#include  and PARENT.H contains #include &quot;child.h&quot; the search for CHILD.H will take place in the following order: 1. The parent directory--in this case, the directory in which PARENT.H

was previously found. 2. If CHILD.H is not there, the directory that contains GRANDMA.C  will be searched next. 3. If CHILD.H is still not found, the directories (if any) specified in /I switches on the CL command line will be searched in left-to- right order. 4. If CHILD.H is still not found, the directories (if any) specified by the INCLUDE environment variable will be searched in left-to- right order. 5. If CHILD.H was not found in any of these places, the compiler will issue the following error:

fatal error C1015: cannot open include file 'child.h'

The Microsoft C/C++ compiler included with Visual C++, 32-bit edition, will issue the following error:

fatal error C1083: Cannot open include file: 'child.h': No such file or directory Additional query words: 8.00 8.00c 9.00 Keywords         : kbCompiler Version          : MS-DOS:6.0,6.00a,6.00ax,7.0; OS/2:6.0,6.00a;  WINDOWS:1.0,1.5; WINDOWS NT:1.0,2.0,4.0,5.0 Platform         : MS-DOS NT OS/2 WINDOWS Issue type       : kbinfo
 * }