[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
gnatgcc
This chapter discusses how to compile Ada programs using the gnatgcc
command. It also describes the set of switches
that can be used to control the behavior of the compiler.
3.1 Compiling Programs 3.2 Switches for gnatgcc
3.3 Search Paths and the Run-Time Library (RTL) 3.4 Order of Compilation Issues 3.5 Examples
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The first step in creating an executable program is to compile the units
of the program using the gnatgcc
command. You must compile the
following files:
You need not compile the following files
because they are compiled as part of compiling related units. GNAT package specs when the corresponding body is compiled, and subunits when the parent is compiled. If you attempt to compile any of these files, you will get one of the following error messages (where fff is the name of the file you compiled):
No code generated for file fff (package spec) No code generated for file fff (subunit) |
The basic command for compiling a file containing an Ada unit is
$ gnatgcc -c [switches] `file name' |
where file name is the name of the Ada file (usually
having an extension
`.ads' for a spec or `.adb' for a body).
You specify the
-c
switch to tell gnatgcc
to compile, but not link, the file.
The result of a successful compilation is an object file, which has the
same name as the source file but an extension of `.o' and an Ada
Library Information (ALI) file, which also has the same name as the
source file, but with `.ali' as the extension. GNAT creates these
two output files in the current directory, but you may specify a source
file in any directory using an absolute or relative path specification
containing the directory information.
gnatgcc
is actually a driver program that looks at the extensions of
the file arguments and loads the appropriate compiler. For example, the
GNU C compiler is `cc1', and the Ada compiler is `gnat1'.
These programs are in directories known to the driver program (in some
configurations via environment variables you set), but need not be in
your path. The gnatgcc
driver also calls the assembler and any other
utilities needed to complete the generation of the required object
files.
It is possible to supply several file names on the same gnatgcc
command. This causes gnatgcc
to call the appropriate compiler for
each file. For example, the following command lists three separate
files to be compiled:
$ gnatgcc -c x.adb y.adb z.c |
calls gnat1
(the Ada compiler) twice to compile `x.adb' and
`y.adb', and cc1
(the C compiler) once to compile `z.c'.
The compiler generates three object files `x.o', `y.o' and
`z.o' and the two ALI files `x.ali' and `y.ali' from the
Ada compilations. Any switches apply to all the files listed,
except for
-gnatx
switches, which apply only to Ada compilations.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
gnatgcc
The gnatgcc
command accepts numerous switches to control the
compilation process. These switches are fully described in this section.
-b target
-Bdir
gnat1
, the Ada compiler)
from dir instead of the default location. Only use this switch
when multiple versions of the GNAT compiler are available. See the
gnatgcc
manual page for further details. You would normally use the
-b
or -V
switch instead.
-c
Note that you may not use gnatgcc
without a -c
switch to
compile and link in one step. This is because the binder must be run,
and currently gnatgcc
cannot be used to run the GNAT binder.
-g
-g
switch
if you plan on using the debugger.
-Idir
-I-
-o file
gnatgcc
to redirect the generated object file
and its associated ALI file. Beware of this switch with GNAT, because it may
cause the object file and ALI file to have different names which in turn
may confuse the binder and the linker.
-O[n]
-O
appears
-O
without
an operand.
-S
-c
to
cause the assembler source file to be
generated, using `.s' as the extension,
instead of the object file.
This may be useful if you need to examine the generated assembly code.
-v
gnatgcc
driver. Normally used only for
debugging purposes or if you need to be sure what version of the
compiler you are executing.
-V ver
gnatgcc
version, not the GNAT version.
-Wuninitialized
-O
switch (in other words, This switch works only if
optimization is turned on).
-gnata
Pragma Assert
and pragma Debug
to be
activated.
-gnatb
stderr
even if verbose mode set.
-gnatc
-gnatD
-gnate
-gnatE
-gnatf
-gnatg
-gnatG
-gnatic
-gnath
stdout
.
-gnatkn
k
= krunch).
-gnatl
-gnatmn
-gnatn
inline
is specified.
-gnatN
inline
is specified. This is equivalent
to using -gnatn
and adding a pragma inline
for every
subprogram in the program.
-fno-inline
-gnato
-gnatp
-gnatq
-gnatP
-gnatR
-gnats
-gnatt
-gnatu
-gnatU
-gnatv
stdout
.
-gnatwm
s,e,l
for suppress, treat as error, elaboration
warnings).
-gnatWe
-gnatx
-gnatwm
-gnaty
-gnatzm
-gnat83
-gnat95
You may combine a sequence of GNAT switches into a single switch. For example, the combined switch
-gnatcfi3 |
is equivalent to specifying the following sequence of switches:
-gnatc -gnatf -gnati3 |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The standard default format for error messages is called "brief format."
Brief format messages are written to stdout
(the standard output
file) and have the following form:
e.adb:3:04: Incorrect spelling of keyword "function" e.adb:4:20: ";" should be "is" |
The first integer after the file name is the line number in the file,
and the second integer is the column number within the line.
emacs
can parse the error messages
and point to the referenced character.
The following switches provide control over the error message
format:
-gnatv
stdout
. The same program compiled with the
-gnatv
switch would generate:
3. funcion X (Q : Integer) | >>> Incorrect spelling of keyword "function" 4. return Integer; | >>> ";" should be "is" |
The vertical bar indicates the location of the error, and the `>>>' prefix can be used to search for error messages. When this switch is used the only source lines output are those with errors.
-gnatl
l
stands for list.
This switch causes a full listing of
the file to be generated. The output might look as follows:
1. procedure E is 2. V : Integer; 3. funcion X (Q : Integer) | >>> Incorrect spelling of keyword "function" 4. return Integer; | >>> ";" should be "is" 5. begin 6. return Q + Q; 7. end; 8. begin 9. V := X + X; 10.end E; |
When you specify the -gnatv
or -gnatl
switches and
standard output is redirected, a brief summary is written to
stderr
(standard error) giving the number of error messages and
warning messages generated.
-gnatU
-gnatb
b
stands for brief.
This switch causes GNAT to generate the
brief format error messages to stdout
as well as the verbose
format message or full listing.
-gnatmn
m
stands for maximum.
n is a decimal integer in the
range of 1 to 999 and limits the number of error messages to be
generated. For example, using -gnatm2
might yield
e.adb:3:04: Incorrect spelling of keyword "function" e.adb:5:35: missing ".." fatal error: maximum errors reached compilation abandoned |
-gnatf
f
stands for full.
Normally, the compiler suppresses error messages that are likely to be
redundant. This switch causes all error
messages to be generated. In particular, in the case of
references to undefined variables. If a given variable is referenced
several times, the normal format of messages is
e.adb:7:07: "V" is undefined (more references follow) |
where the parenthetical comment warns that there are additional
references to the variable V
. Compiling the same program with the
-gnatf
switch yields
e.adb:7:07: "V" is undefined e.adb:8:07: "V" is undefined e.adb:8:12: "V" is undefined e.adb:8:16: "V" is undefined e.adb:9:07: "V" is undefined e.adb:9:12: "V" is undefined |
-gnatq
q
stands for quit (really "don't quit").
In normal operation mode, the compiler first parses the program and
determines if there are any syntax errors. If there are, appropriate
error messages are generated and compilation is immediately terminated.
This switch tells
GNAT to continue with semantic analysis even if syntax errors have been
found. This may enable the detection of more errors in a single run. On
the other hand, the semantic analyzer is more likely to encounter some
internal fatal error when given a syntactically invalid tree.
-gnate
-gnate
may cause error messages to be
generated out of sequence and also disconnects a number of useful
error message processing circuits. This switch should be used only
in error situations where the compiler terminates with no output
at all, or goes into an infinite loop. In such cases, the
-gnate
switch may be used to see if any error situations
were detected before the compiler crash (see section 20.9 GNAT Abnormal Termination).
In addition to error messages, which correspond to illegalities as defined in the Ada 95 Reference Manual, the compiler detects two kinds of warning situations.
First, the compiler considers some constructs suspicious and generates a warning message to alert you to a possible error. Second, if the compiler detects a situation that is sure to raise an exception at run time, it generates a warning message. The following shows an example of warning messages:
e.adb:4:24: warning: creation of object may raise Storage_Error e.adb:10:17: warning: static value out of range e.adb:10:17: warning: "Constraint_Error" will be raised at run time |
GNAT considers a large number of situations as appropriate
for the generation of warning messages. As always, warnings are not
definite indications of errors. For example, if you do an out-of-range
assignment with the deliberate intention of raising a
Constraint_Error
exception, then the warning that may be
issued does not indicate an error. Some of the situations for which GNAT
issues warnings (at least some of the time) are:
Four switches are available to control the handling of warning messages:
-gnatwe (treat warnings as errors)
-gnatws (suppress warnings)
-gnatwl (warn on elaboration order errors)
-gnatwu (warn on unused entities)
with
'ed
and not
referenced. In the case of packages, a warning is also generated if
no entities in the package are referenced. This means that if the package
is referenced but the only references are in use
clauses or renames
declarations, a warning is still generated. A warning is also generated
for a generic package that is with
'ed but never instantiated.
-gnatR
-gnatR
causes the compiler to output a listing
showing representation information for declared array and record types,
including record representation clauses.
-gnatx
gnatfind
and gnatxref
. The -gnatx switch
suppresses this information. This saves some space and may slightly
speed up compilation, but means that these tools cannot be used.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
-gnata
The pragmas Assert
and Debug
normally have no effect and
are ignored. This switch, where `a' stands for assert, causes
Assert
and Debug
pragmas to be activated.
The pragmas have the form:
pragma Assert (Boolean-expression [, static-string-expression]) pragma Debug (procedure call) |
The Assert
pragma causes Boolean-expression to be tested.
If the result is True
, the pragma has no effect (other than
possible side effects from evaluating the expression). If the result is
False
, the exception Assert_Error
declared in the package
System.Assertions
is
raised (passing static-string-expression, if present, as the
message associated with the exception). If no string expression is
given the default is a string giving the file name and line number
of the pragma.
The Debug
pragma causes procedure to be called. Note that
pragma Debug
may appear within a declaration sequence, allowing
debugging procedures to be called between declarations.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The -gnatyx switch causes the compiler to enforce specified style rules. A limited set of style rules has been used in writing the GNAT sources themselves. This switch allows user programs to activate all or some of these checks. If the source program fails a specified style check, an appropriate error message is given, preceded by the character sequence "(style)", and the program is considered illegal. The string x is a sequence of letters or digits indicating the particular style checks to be performed. The following checks are defined:
1-9 (specify indentation level)
-gnaty
then proper
indentation is checked, with the digit indicating the indentation level
required. The general style of required indentation is as specified by
the examples in the Ada Reference Manual. Full line comments must be
aligned with the --
starting on a column that is a multiple of
the alignment level.
a (check attribute casing)
-gnaty
then
attribute names, including the case of keywords such as digits
used as attributes names, must be written in mixed case, that is, the
initial letter and any letter following an underscore must be uppercase.
All other letters must be lowercase.
b (blanks not allowed at statement end)
-gnaty
then
trailing blanks are not allowed at the end of statements. The purpose of this
rule, together with h (no horizontal tabs), is to enforce a canonical format
for the use of blanks to separate source tokens.
c (check comments)
-gnaty
then
comments must meet the following set of rules:
gnatprep
tool.
--------------------------- -- This is a box comment -- -- with two text lines. -- --------------------------- |
e (check end labels)
-gnaty
then
optional labels on end
statements ending subprograms are required to be
present.
f (no form feeds or vertical tabs)
-gnaty
then
neither form feeds nor vertical tab characters are not permitted
in the source text.
h (no horizontal tabs)
-gnaty
then
horizontal tab characters are not permitted in the source text.
Together with the b (no blanks at end of line) check, this
enforces a canonical form for the use of blanks to separate
source tokens.
i (check if-then layout)
-gnaty
,
then the keyword then
must appear either on the same
line as corresponding if
, or on a line on its own, lined
up under the if
with at least one non-blank line in between
containing all or part of the condition to be tested.
k (check keyword casing)
-gnaty
then
all keywords must be in lower case (with the exception of keywords
such as digits
used as attribute names to which this check
does not apply).
l (check layout)
-gnaty
then
layout of statement and declaration constructs must follow the
recommendations in the Ada Reference Manual, as indicated by the
form of the syntax rules. For example an else
keyword must
be lined up with the corresponding if
keyword.
There are two respects in which the style rule enforced by this check
option are more liberal than those in the Ada Reference Manual. First
in the case of record declarations, it is permissible to put the
record
keyword on the same line as the type
keyword, and
then the end
in end record
must line up under type
.
For example, either of the following two layouts is acceptable:
type q is record a : integer; b : integer; end record; type q is record a : integer; b : integer; end record; |
Second, in the case of a block statement, a permitted alternative
is to put the block label on the same line as the declare
or
begin
keyword, and then line the end
keyword up under
the block label. For example both the following are permitted:
Block : declare A : Integer := 3; begin Proc (A, A); end Block; Block : declare A : Integer := 3; begin Proc (A, A); end Block; |
The same alternative format is allowed for loops. For example, both of the following are permitted:
Clear : while J < 10 loop A (J) := 0; end loop Clear; Clear : while J < 10 loop A (J) := 0; end loop Clear; |
m (check maximum line length)
-gnaty
then the length of source lines must not exceed 79 characters, including
any trailing blanks. The value of 79 allows convenient display on an
80 character wide device or window, allowing for possible special
treatment of 80 character lines.
Mnnn (set maximum line length)
-gnaty
then the length of lines must not exceed the
given value.
p (check pragma casing)
-gnaty
then
pragma names must be written in mixed case, that is, the
initial letter and any letter following an underscore must be uppercase.
All other letters must be lowercase.
r (check references)
-gnaty
then all identifier references must be cased in the same way as the
corresponding declaration. No specific casing style is imposed on
identifiers. The only requirement is for consistency of references
with declarations.
s (check separate specs)
-gnaty
then
separate declarations ("specs") are required for subprograms (a
body is not allowed to serve as its own declaration). The only
exception is that parameterless library level procedures are
not required to have a separate declaration. This exception covers
the most frequent form of main program procedures.
t (check token spacing)
-gnaty
then
the following token spacing rules are enforced:
abs
and not
must be followed by a space.
=>
must be surrounded by spaces.
<>
must be preceded by a space or a left parenthesis.
**
must be surrounded by spaces.
There is no restriction on the layout of the **
binary operator.
In the above rules, appearing in column one is always permitted, that is, counts as meeting either a requirement for a required preceding space, or as meeting a requirement for no preceding space.
Appearing at the end of a line is also always permitted, that is, counts as meeting either a requirement for a following space, or as meeting a requirement for no following space.
The switch
-gnaty
on its own (that is not followed by any letters or digits),
is equivalent to gnaty3abcefhiklmprst
, that is all checking
options are enabled, with an indentation level of 3. This is the standard
checking option that is used for the GNAT sources.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If you compile with the default options, GNAT will insert many run-time
checks into the compiled code, including code that performs range
checking against constraints, but not arithmetic overflow checking for
integer operations (including division by zero) or checks for access
before elaboration on subprogram calls. All other run-time checks, as
required by the Ada 95 Reference Manual, are generated by default.
The following gnatgcc
switches refine this default behavior:
-gnatp
pragma Suppress (all_checks
)
had been present in the source. Use this switch to improve the performance
of the code at the expense of safety in the presence of invalid data or
program bugs.
-gnato
Constraint_Error
as required by Ada
semantics).
Note that the -gnato
switch does not affect the code generated
for any floating-point operations; it applies only to integer
operations. For floating-point, GNAT has the Machine_Overflows
attribute set to False
and the normal mode of operation is to
generate IEEE NaN and infinite values on overflow or invalid operations
(such as dividing 0.0 by 0.0).
-gnatE
gnatgcc
.
The setting of these switches only controls the default setting of the
checks. You may modify them using either Suppress
(to remove
checks) or Unsuppress
(to add back suppressed checks) pragmas in
the program source.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
gnatgcc
for Syntax Checking -gnats
The s
stands for syntax.
Run GNAT in syntax checking only mode. For example, the command
$ gnatgcc -c -gnats x.adb |
compiles file `x.adb' in syntax-check-only mode. You can check a
series of files in a single command
, and can use wild cards to specify such a group of files.
Note that you must specify the -c
(compile
only) flag in addition to the -gnats
flag.
.
You may use other switches in conjunction with -gnats
. In
particular, -gnatl
and -gnatv
are useful to control the
format of any generated error messages.
The output is simply the error messages, if any. No object file or ALI
file is generated by a syntax-only compilation. Also, no units other
than the one specified are accessed. For example, if a unit X
with
's a unit Y
, compiling unit X
in syntax
check only mode does not access the source file containing unit
Y
.
Normally, GNAT allows only a single unit in a source file. However, this
restriction does not apply in syntax-check-only mode, and it is possible
to check a file containing multiple compilation units concatenated
together. This is primarily used by the gnatchop
utility
(see section 7. Renaming Files Using gnatchop
).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
gnatgcc
for Semantic Checking -gnatc
The c
stands for check.
Causes the compiler to operate in semantic check mode,
with full checking for all illegalities specified in the
Ada 95 Reference Manual, but without generation of any source code (no object
or ALI file generated).
Because dependent files must be accessed, you must follow the GNAT semantic restrictions on file structuring to operate in this mode:
The output consists of error messages as appropriate. No object file or ALI file is generated. The checking corresponds exactly to the notion of legality in the Ada 95 Reference Manual.
Any unit can be compiled in semantics-checking-only mode, including units that would not normally be compiled (subunits, and specifications where a separate body is present).
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
-gnat83
Although GNAT is primarily an Ada 95 compiler, it accepts this switch to
specify that an Ada 83 program is to be compiled in Ada83 mode. If you specify
this switch, GNAT rejects most Ada 95 extensions and applies Ada 83 semantics
where this can be done easily.
It is not possible to guarantee this switch does a perfect
job; for example, some subtle tests, such as are
found in earlier ACVC tests (that have been removed from the ACVC suite for Ada
95), may not compile correctly. However, for most purposes, using
this switch should help to ensure that programs that compile correctly
under the -gnat83
switch can be ported easily to an Ada 83
compiler. This is the main use of the switch.
With few exceptions (most notably the need to use <>
on
unconstrained generic formal parameters, the use of the new Ada 95
keywords, and the use of packages
with optional bodies), it is not necessary to use the
-gnat83
switch when compiling Ada 83 programs, because, with rare
exceptions, Ada 95 is upwardly compatible with Ada 83. This
means that a correct Ada 83 program is usually also a correct Ada 95
program.
-gnat95
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
-gnatr
Normally, GNAT permits any source layout consistent with the Ada 95
reference manual requirements. This switch
(`r' is for "reference manual")
enforces the layout conventions suggested by the examples and syntax
rules of the Ada 95 Language Reference Manual. For example, an else
must line up with an if
and code in the then
and
else
parts must be indented. The compiler treats violations of
the layout rules as syntax errors if you specify this switch.
-gnatg
-gnatg
switch specified.
You can find the full documentation for the style conventions imposed by
-gnatg
in the body of the package Style
in the
compiler sources (in the file `style.adb').
You should not normally use the -gnatg
switch. However, you
must use -gnatg
for compiling any language-defined unit,
or for adding children to any language-defined unit other than
Standard
.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
-gnatic
Normally GNAT recognizes the Latin-1 character set in source program identifiers, as described in the Ada 95 Reference Manual. This switch causes GNAT to recognize alternate character sets in identifiers. c is a single character indicating the character set, as follows:
1
2
3
4
p
8
f
n
w
See section 2.2 Foreign Language Representation, for full details on the implementation of these character sets.
-gnatWe
h
u
s
e
8
b
-gnatW8
specifies that both
brackets and UTF-8
encodings will be recognized. The units that are
with'ed directly or indirectly will be scanned using the specified
representation scheme, and so if one of the non-brackets scheme is
used, it must be used consistently throughout the program. However,
since brackets encoding is always recognized, it may be conveniently
used in standard libraries, allowing these libraries to be used with
any of the available coding schemes.
scheme. If no -gnatW?
parameter is present, then the default
representation is Brackets encoding only.
Note that the wide character representation that is specified (explicitly or by default) for the main program also acts as the default encoding used for Wide_Text_IO files if not specifically overridden by a WCEM form parameter.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
-gnatkn
For the source file naming rules, See section 2.3 File Naming Rules.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
-gnatn
n
here is intended to suggest the first syllable of the
word "inline".
GNAT recognizes and processes Inline
pragmas. However, for the
inlining to actually occur, optimization must be enabled. To enable
inlining across unit boundaries, this is, inlining a call in one unit of
a subprogram declared in a with
'ed unit, you must also specify
this switch.
In the absence of this switch, GNAT does not attempt
inlining across units and does not need to access the bodies of
subprograms for which pragma Inline
is specified if they are not
in the current unit.
If you specify this switch the compiler will access these bodies, creating an extra source dependency for the resulting object file, and where possible, the call will be inlined. For further details on when inlining is possible see See section 21.3 Inlining of Subprograms.
-gnatN
Inline
for every subprogram referenced by the compiled
unit.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
-gnatt
-gnatu
stdout
.
The listing includes all units on which the unit being compiled depends
either directly or indirectly.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
-gnatdx
Debug
unit in the compiler source
file `debug.adb'.
-gnatG
-gnatG
you can identify
these cases, and consider whether it may be desirable to modify the coding
approach to improve efficiency.
The format of the output is very similar to standard Ada source, and is easily understood by an Ada programmer. The following special syntactic additions correspond to low level features used in the generated code that do not have any exact analogies in pure Ada source form:
-gnatD
-gnatG
to cause the expanded
source, as described above to be written to files with names
`xxx.dg', where `xxx' is the normal file name,
for example, if the source file name is `hello.adb',
then a file `hello.adb.dg' will be written.
The debugging information generated
by the gnatgcc
-g
switch will refer to the generated
`xxx.dg' file. This allows you to do source level debugging using
the generated code which is sometimes useful for complex code, for example
to find out exactly which part of a complex construction raised an
exception.
new xxx [storage_pool = yyy]
at end procedure-name;
(if expr then expr else expr)
x?y:z
construction in C.
target^(source)
target?(source)
target?^(source)
x #/ y
x #mod y
x #* y
x #rem y
free expr [storage_pool = xxx]
free
statement.
freeze typename [actions]
reference itype
function-name! (arg, arg, arg)
labelname : label
expr && expr && expr ... && expr
[constraint_error]
Constraint_Error
exception.
expression'reference
target-type!(source-expression)
[numerator/denominator]
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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 gnatgcc
command line, in the order given.
ADA_INCLUDE_PATH
environment variable.
Construct this value
exactly as the PATH
environment variable: a list of directory
names separated by colons.
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, gnatgcc
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 routines. 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.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
If, in our earlier example, there was a spec for the hello
procedure, it would be contained in the file `hello.ads'; yet this
file would not have to be explicitly compiled. This is the result of the
model we chose to implement library management. Some of the consequences
of this model are as follows:
with
's, all its subunits, and the bodies of any generics it
instantiates must be available (reachable by the search-paths mechanism
described above), or you will receive a fatal error message.
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following are some typical Ada compilation command line examples:
$ gnatgcc -c xyz.adb
$ gnatgcc -c -O2 -gnata xyz-def.adb
Compile the child unit package in file `xyz-def.adb' with extensive
optimizations, and pragma Assert
/Debug
statements
enabled.
$ gnatgcc -c -gnatc abc-def.adb
[ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |