2.2.2. Included files

Several factors affect the way the ARM compilers search for #include header files and source files. These include:

The in-memory file system

The ARM compilers have the ANSI C library headers built into a special, textually-compressed, in-memory file system. By default, the C header files are used from this file system for applications built from the command line. You can specify the in-memory file system on the command line with -j- or -I-.

The C++ header files that are equivalent to the C library header files are also stored in the in-memory file system. The header files specific to C++, such as iostream, are not stored in the in-memory file system.

Enclosing a filename in angle brackets, #include <stdio.h> for example, indicates that the included file is a system file and instructs the compiler to look in the in-memory file system first.

Enclosing a filename in double quotes, #include "myfile.h" for example, indicates that it is not a system file and instructs the compiler to look in the search path.

The current place

By default, the ARM compilers use Berkeley UNIX search rule, so source files and #include header files are searched for relative to the current place. This is the directory containing the source or header file currently being processed by the compiler.

When a file is found relative to an element of the search path, the directory containing that file becomes the new current place. When the compiler has finished processing that file, it restores the previous current place. At each instant there is a stack of current places corresponding to the stack of nested #include directives. For example, if the current place is install_directory\include and the compiler is seeking the include file sys\defs.h, it locates install_directory\include\sys\defs.h if it exists.

When the compiler begins to process defs.h, the current place becomes install_directory\include\sys. Any file included by defs.h that is not specified with an absolute pathname, is sought relative to install_directory\include\sys.

The original current place install_directory\include is restored only when the compiler has finished processing defs.h.

You can disable the stacking of current places by using the compiler option -fk. This option makes the compiler use the search rule originally described by Kernighan and Ritchie in The C Programming Language. Under this rule each nonrooted user #include is sought relative to the directory containing the source file that is being compiled.

The ARMINC environment variable

You can set the ARMINC environment variable to a comma-separated list of directories to control searching for included header and source files. For example, from a Windows command line, type:

set ARMINC=c:\work\x,c:\work\y

When compiling from the command line, directories specified with ARMINC are searched immediately after directories specified by the -I option on the command line have been searched. If the -j option is used, ARMINC is ignored.

The search path

Table 2.2 shows how the various command-line options affect the search path used by the compiler when it searches for included header and source files. The following conventions are used in the table:

:mem

The in-memory file system where the ARM compilers store ANSI C and some C++ header files. See The in-memory file system for more information.

ARMINC

The list of directories specified by the ARMINC environment variable, if it is set.

CP

The current place. See The current place for more information.

Idir and jdirs

The directories specified by the -I and -j compiler options.

Table 2.2. Include file search paths

Compiler option<include>"include"
Neither -I or -j:mem and ARMINCCP, ARMINC, and :mem
-jjdirsCP and jdirs
-I:mem, ARMINC, and IdirsCP, Idirs, ARMINC, and :mem
Both -I and -jIdirs and jdirsCP, Idirs, and jdirs
-fdNo effectRemoves CP from the search path, so the search is now the same as that invoked with angle brackets
-fkNo effectUses Kernighan and Ritchie search rules
Copyright © 1999-2001 ARM Limited. All rights reserved.ARM DUI 0067D
Non-Confidential