With the GNAT source-based library system, the compiler must be able to find source files for units that are needed by the unit being compiled. Search paths are used to guide this process.
The compiler compiles one source file whose name must be given explicitly on the command line. In other words, no searching is done for this file. To find all other source files that are needed (the most common being the specs of units), the compiler examines the following directories, in the following order:
-I
switch given on the gcc
command line, in the order given.
ADA_PRJ_INCLUDE_FILE
environment variable.
ADA_PRJ_INCLUDE_FILE
is normally set by gnatmake or by the gnat
driver when project files are used. It should not normally be set
by other means.
ADA_INCLUDE_PATH
environment variable.
Construct this value
exactly as the
PATH
environment variable: a list of directory
names separated by colons (semicolons when working with the NT version).
ada_source_path
file which is part of the GNAT
installation tree and is used to store standard libraries such as the
GNAT Run Time Library (RTL) source files.
Installing a library
Specifying the switch -I-
inhibits the use of the directory
containing the source file named in the command line. You can still
have this directory on your search path, but in this case it must be
explicitly requested with a -I
switch.
Specifying the switch -nostdinc
inhibits the search of the default location for the GNAT Run Time
Library (RTL) source files.
The compiler outputs its object files and ALI files in the current
working directory.
Caution: The object file can be redirected with the -o
switch;
however, gcc
and gnat1
have not been coordinated on this
so the ALI
file will not go to the right place. Therefore, you should
avoid using the -o
switch.
The packages Ada
, System
, and Interfaces
and their
children make up the GNAT RTL, together with the simple System.IO
package used in the "Hello World"
example. The sources for these units
are needed by the compiler and are kept together in one directory. Not
all of the bodies are needed, but all of the sources are kept together
anyway. In a normal installation, you need not specify these directory
names when compiling or binding. Either the environment variables or
the built-in defaults cause these files to be found.
In addition to the language-defined hierarchies (System
, Ada
and
Interfaces
), the GNAT distribution provides a fourth hierarchy,
consisting of child units of GNAT
. This is a collection of generally
useful types, subprograms, etc. See the GNAT_Reference_Manual
for further details.
Besides simplifying access to the RTL, a major use of search paths is in compiling sources from multiple directories. This can make development environments much more flexible.