| |||
| Home > The ARM Compilers > File usage > Included files | |||
There are a number of factors that affect how the ARM compilers
search for #include header files and source files.
These include:
The -I and -j compiler
options.
The -fk and -fd compiler
options.
The value of the environment variable ARMINC.
Whether the filename is an absolute filename or a relative filename.
Whether the filename is between angle brackets or double quotes. This determines whether or not the file is sought in 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. The in-memory
file system can be specified explicitly on the command line as -j- and -I-.
In addition, the C++ header files that are equivalent to the
C library header files are also stored in the in-memory file system.
The Rogue Wave library header files, and the ARM-supplied headers
such as iostream.h are not stored in the in-memory
file system.
Enclosing a #include filename in angle
brackets indicates that the included file is a system file and ensures
that the compiler looks first in its built-in file system. For example:
#include <stdio.h>
Enclosing a #include filename in double
quotes indicates that it is not a system file. For example:
#include "myfile.h"
In this example, the compiler looks for the specified file in the appropriate search path. Refer to Specifying search paths for detailed information on how the ARM compilers search for include files.
By default, the ARM compilers adopt the search rules used
by Berkeley UNIX systems. Under these rules, source files and #include header
files are searched for relative to the current place.
The current place 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 name of 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 ~/arm250/include and
the compiler is seeking the include file sys/defs.h, it
will locate ~/arm250/include/sys/defs.h if
it exists.
When the compiler begins to process defs.h,
the current place becomes ~/arm250/include/sys.
Any file included by defs.h that is not specified
with an absolute pathname is sought relative to ~/arm250/include/sys.
You can disable the stacking of current places with 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 non-rooted
user #include is sought relative to the directory
containing the source file that is being compiled.
You can set the ARMINC environment
variable to specify a list of directories to be searched for included
header and source files. Directories listed here will be searched immediately
after any directories specified by the -I option
on the command line. If the -j option is used, ARMINC is
ignored.
Table 2.1 shows how the various command-line options affect the search path used by the compiler for included header and source files. The search path is different for double quoted include files and angle bracketed include files. The following conventions are used in the table:
:mem means the in-memory file
system in which the ARM compilers store ANSI C and some C++ header
files. See The in-memory file system for
more information.
ARMINC is the list of directories
specified by the ARMINC environment variable,
if it is set.
CP is the current place. See The current place for more information.
Idir and jdirs are
the directories specified by the -I and -j compiler
options. Note that multiple -I options may be specified
and that directories specified by -I are searched
before directories specified by -j, irrespective
of their relative order on the command line. To specify the in-memory
file system use -I-, or -j-.
Table 2.1. Include file search paths
| Compiler Option | <include> | "include.h" |
|---|---|---|
not -I or -j | :mem, ARMINC | CP, ARMINC,:mem |
-j | jdirs | CP, jdirs |
-I | :mem, Idirs, ARMINC | CP, Idirs, ARMINC, :mem |
both -I and -j | Idirs, jdirs | CP, Idirs, jdirs |
-fd | no effect | Removes CP from the search
path. Double quoted include files are searched for in the same way
as angle bracketed include files. |
-fk | no effect | Makes CP follow Kernighan
and Ritchie search rules. |