Compile your program to run on
target, which is the name of a
system configuration. You must have a GNAT cross-compiler built if
target is not the same as your host system.
Load compiler executables (for example,
gnat1, the Ada compiler)
dir instead of the default location. Only use this switch
when multiple versions of the GNAT compiler are available.
See the "Options for Directory Search" section in the
Using the GNU Compiler Collection (GCC) manual for further details.
You would normally use the
-V switch instead.
Compile. Always use this switch when compiling Ada programs.
Note: for some other languages when using
gcc, notably in
the case of C and C++, it is possible to use
gcc without a
-c switch to
compile and link in one step. In the case of GNAT, you
cannot use this approach, because the binder must be run
gcc cannot be used to run the GNAT binder.
Makes the compiler output callgraph information for the program, on a
per-file basis. The information is generated in the VCG format. It can
be decorated with additional, per-node and/or per-edge information, if a
list of comma-separated markers is additionally specified. When the
su marker is specified, the callgraph is decorated with stack usage
information; it is equivalent to
-fstack-usage. When the
marker is specified, the callgraph is decorated with information about
dynamically allocated objects.
Generates SCO (Source Coverage Obligation) information in the ALI file.
This information is used by advanced coverage tools. See unit
in the compiler sources for details in files
This switch controls the balance between GNAT encodings and standard DWARF emitted in the debug information.
Enables Link Time Optimization. This switch must be used in conjunction
-Ox switches (but not with the
since it is a full replacement for the latter) and instructs the compiler
to defer most optimizations until the link stage. The advantage of this
approach is that the compiler can do a whole-program analysis and choose
the best interprocedural optimization strategy based on a complete view
of the program, instead of a fragmentary view with the usual approach.
This can also speed up the compilation of big programs and reduce the
size of the executable, compared with a traditional per-unit compilation
with inlining across units enabled by the
The drawback of this approach is that it may require more memory and that
the debugging information generated by -g with it might be hardly usable.
The switch, as well as the accompanying
-Ox switches, must be
specified both for the compilation and the link phases.
n parameter is specified, the optimization and final code
generation at link time are executed using
n parallel jobs by
means of an installed
Suppresses all inlining, unless requested with pragma
effect is enforced regardless of other optimization or inlining switches.
Note that inlining can also be suppressed on a finer-grained basis with
Suppresses automatic inlining of subprograms, which is enabled
-O3 is used.
Suppresses automatic inlining of small subprograms, which is enabled
-O2 is used.
Suppresses inlining of subprograms local to the unit and called once
from within it, which is enabled if
-O1 is used.
Suppresses high-level loop induction variable optimizations, which are
-O1 is used. These optimizations are generally
profitable but, for some specific cases of loops with numerous uses
of the iteration variable that follow a common pattern, they may end
up destroying the regularity that could be exploited at a lower level
and thus producing inferior code.
Causes the compiler to avoid assumptions regarding non-aliasing of objects of different types. See Optimization and Strict Aliasing for details.
Causes the compiler to avoid assumptions regarding the rules of signed
integer overflow. These rules specify that signed integer overflow will
result in a Constraint_Error exception at run time and are enforced in
default mode by the compiler, so this switch should not be necessary in
normal operating mode. It might be useful in conjunction with
for very peculiar cases of low-level programming.
Activates stack checking. See Stack Overflow Checking for details.
Makes the compiler output stack usage information for the program, on a per-subprogram basis. See Static Stack Usage Analysis for details.
Generate debugging information. This information is stored in the object
file and copied from there to the final executable file by the linker,
where it can be read by the debugger. You must use the
-g switch if you plan on using the debugger.
Allow full Ada 2005 features.
Allow full Ada 2012 features.
Allow full Ada 2005 features (same as
Allow full Ada 2012 features (same as
Enforce Ada 83 restrictions.
Enforce Ada 95 restrictions.
Note: for compatibility with some Ada 95 compilers which support only
overriding keyword of Ada 2005, the
-gnatd.D switch can
be used along with
-gnat95 to achieve a similar effect with GNAT.
-gnatd.D instructs GNAT to consider
overriding as a keyword
and handle its associated semantic checks, even in Ada 95 mode.
Pragma Assert and
pragma Debug to be
activated. Note that these pragmas can also be controlled using the
It also activates pragmas
Postcondition. Note that these pragmas can also be controlled
using the configuration pragma
Check_Policy. In Ada 2012, it
also activates all assertions defined in the RM as aspects: preconditions,
postconditions, type invariants and (sub)type predicates. In all Ada modes,
corresponding pragmas for type invariants and (sub)type predicates are
also activated. The default is that all these assertions are disabled,
and have no effect, other than being checked for syntactic validity, and
in the case of subtype predicates, constructions such as membership tests
still test predicates even if assertions are turned off.
gnat.adc. If a
gnat.adc file is present,
it will be ignored.
Generate brief messages to
stderr even if verbose mode set.
Assume no invalid (bad) values except for ’Valid attribute use (Validity Checking).
Check syntax and semantics only (no code generation attempted). When the
compiler is invoked by
gnatmake, if the switch
only given to the compiler (after
-cargs or in package Compiler of
the project file,
gnatmake will fail because it will not find the
object file after compilation. If
gnatmake is called with
-gnatc as a builder switch (before
-cargs or in package
Builder of the project file) then
gnatmake will not fail because
it will not look for the object files after compilation, and it will not try
to build and link.
Generate CodePeer intermediate format (no code generation attempted).
This switch will generate an intermediate representation suitable for
use by CodePeer (
.scil files). This switch is not compatible with
code generation (it will, among other things, disable some switches such
as -gnatn, and enable others such as -gnata).
Specify debug options for the compiler. The string of characters after
-gnatd specify the specific debug options. The possible
characters are 0-9, a-z, A-Z, optionally preceded by a dot. See
compiler source file
debug.adb for details of the implemented
debug options. Certain debug options are relevant to applications
programmers, and these are documented at appropriate points in this
Create expanded source files for source level debugging. This switch
also suppresses generation of cross-reference information
-gnatx). Note that this switch is not allowed if a previous
-gnatR switch has been given, since these two switches are not compatible.
Check that the actual parameters of a subprogram call are not aliases of one another. To qualify as aliasing, the actuals must denote objects of a composite type, their memory locations must be identical or overlapping, and at least one of the corresponding formal parameters must be of mode OUT or IN OUT.
type Rec_Typ is record Data : Integer := 0; end record; function Self (Val : Rec_Typ) return Rec_Typ is begin return Val; end Self; procedure Detect_Aliasing (Val_1 : in out Rec_Typ; Val_2 : Rec_Typ) is begin null; end Detect_Aliasing; Obj : Rec_Typ; Detect_Aliasing (Obj, Obj); Detect_Aliasing (Obj, Self (Obj));
In the example above, the first call to
Detect_Aliasing fails with a
Program_Error at run time because the actuals for
Val_2 denote the same object. The second call executes without raising
an exception because
Self(Obj) produces an anonymous object which does
not share the memory location of
Specify a configuration pragma file (the equal sign is optional) (The Configuration Pragmas Files).
Generate CodePeer messages in a compiler-like format. This switch is only
-gnatcC is also specified and requires an installation
Disable atomic synchronization
Defines a symbol, associated with
value, for preprocessing.
Generate extra information in exception messages. In particular, display extra column information and the value and range associated with index and range check failures, and extra column information for access checks. In cases where the compiler is able to determine at compile time that a check will fail, it gives a warning, and the extra information is not produced at run time.
Display full source path name in brief error messages.
Check for overflow on all floating-point operations, including those
for unconstrained predefined types. See description of pragma
Check_Float_Overflow in GNAT RM.
-gnatcswitch must always be specified before this switch, e.g.
-gnatceg. Generate a C header from the Ada input file. See Generating C Headers for Ada Specifications for more information.
Save result of preprocessing in a text file.
Set maximum number of instantiations during compilation of a single unit to
nnn. This may be useful in increasing the default maximum of 8000 for
the rare case when a single unit legitimately exceeds this limit.
Indicates that the source is a multi-unit source and that the index of the
unit to compile is
nnn needs to be a positive number and need
to be a valid index in the multi-unit source.
This switch can be used with the static elaboration model to issue info
pragma Elaborate and
are generated. This is useful in diagnosing elaboration circularities
caused by these implicit pragmas when using the static elaboration
model. See See the section in this guide on elaboration checking for
further details. These messages are not generated by default, and are
intended only for temporary use when debugging circularity problems.
This switch turns off the info messages about implicit elaboration pragmas.
Specify a mapping file (the equal sign is optional) (Units to Sources Mapping Files).
Specify a preprocessing data file (the equal sign is optional) (Integrated Preprocessing).
Turn categorization dependency errors into warnings. Ada requires that units that WITH one another have compatible categories, for example a Pure unit cannot WITH a Preelaborate unit. If this switch is used, these errors become warnings (which can be ignored, or suppressed in the usual manner). This can be useful in some specialized circumstances such as the temporary use of special test software.
-fdump-scos, kept for backwards compatibility.
Generate target dependent information. The format of the output file is
described in the section about switch
Read target dependent information, such as endianness or sizes and alignments of base type. If this switch is passed, the default target dependent information of the compiler is replaced by the one read from the input file. This is used by tools other than the compiler, e.g. to do semantic analysis of programs that will run on some other target than the machine on which the tool is run.
The following target dependent values should be defined,
Nat denotes a natural integer value,
Pos denotes a
positive integer value, and fields marked with a question mark are
boolean fields, where a value of 0 is False, and a value of 1 is True:
Bits_BE : Nat; -- Bits stored big-endian? Bits_Per_Unit : Pos; -- Bits in a storage unit Bits_Per_Word : Pos; -- Bits in a word Bytes_BE : Nat; -- Bytes stored big-endian? Char_Size : Pos; -- Standard.Character'Size Double_Float_Alignment : Nat; -- Alignment of double float Double_Scalar_Alignment : Nat; -- Alignment of double length scalar Double_Size : Pos; -- Standard.Long_Float'Size Float_Size : Pos; -- Standard.Float'Size Float_Words_BE : Nat; -- Float words stored big-endian? Int_Size : Pos; -- Standard.Integer'Size Long_Double_Size : Pos; -- Standard.Long_Long_Float'Size Long_Long_Size : Pos; -- Standard.Long_Long_Integer'Size Long_Size : Pos; -- Standard.Long_Integer'Size Maximum_Alignment : Pos; -- Maximum permitted alignment Max_Unaligned_Field : Pos; -- Maximum size for unaligned bit field Pointer_Size : Pos; -- System.Address'Size Short_Enums : Nat; -- Foreign enums use short size? Short_Size : Pos; -- Standard.Short_Integer'Size Strict_Alignment : Nat; -- Strict alignment? System_Allocator_Alignment : Nat; -- Alignment for malloc calls Wchar_T_Size : Pos; -- Interfaces.C.wchar_t'Size Words_BE : Nat; -- Words stored big-endian?
Bits_Per_Unit is the number of bits in a storage unit, the equivalent of
BITS_PER_UNIT documented as follows: Define this macro to be the number of bits in an addressable storage unit (byte); normally 8.
Bits_Per_Word is the number of bits in a machine word, the equivalent of
BITS_PER_WORD documented as follows: Number of bits in a word; normally 32.
Double_Scalar_Alignment is the alignment for a scalar whose size is two
machine words. It should be the same as the alignment for C
Maximum_Alignment is the maximum alignment that the compiler might choose
by default for a type or object, which is also the maximum alignment that can
be specified in GNAT. It is computed for GCC backends as
/ BITS_PER_UNIT where GCC macro
BIGGEST_ALIGNMENT is documented as
follows: Biggest alignment that any data type can require on this machine, in bits.
Max_Unaligned_Field is the maximum size for unaligned bit field, which is
64 for the majority of GCC targets (but can be different on some targets like
Strict_Alignment is the equivalent of GCC macro
documented as follows: Define this macro to be the value 1 if instructions will fail to work if given data not on the nominal alignment. If instructions will merely go slower in that case, define this macro as 0.
System_Allocator_Alignment is the guaranteed alignment of data returned
by calls to
The format of the input file is as follows. First come the values of the variables defined above, with one line per value:
name is the name of the parameter, spelled out in full,
and cased as in the above list, and
value is an unsigned decimal
integer. Two or more blanks separates the name from the value.
All the variables must be present, in alphabetical order (i.e. the same order as the list above).
Then there is a blank line to separate the two parts of the file. Then come the lines showing the floating-point types to be registered, with one line per registered mode:
name digs float_rep size alignment
name is the string name of the type (which can have
single spaces embedded in the name (e.g. long double),
the number of digits for the floating-point type,
the float representation (I/V/A for IEEE-754-Binary, Vax_Native,
size is the size in bits,
alignment is the
alignment in bits. The name is followed by at least two blanks, fields
are separated by at least one blank, and a LF character immediately
follows the alignment field.
Here is an example of a target parameterization file:
Bits_BE 0 Bits_Per_Unit 8 Bits_Per_Word 64 Bytes_BE 0 Char_Size 8 Double_Float_Alignment 0 Double_Scalar_Alignment 0 Double_Size 64 Float_Size 32 Float_Words_BE 0 Int_Size 64 Long_Double_Size 128 Long_Long_Size 64 Long_Size 64 Maximum_Alignment 16 Max_Unaligned_Field 64 Pointer_Size 64 Short_Size 16 Strict_Alignment 0 System_Allocator_Alignment 16 Wchar_T_Size 32 Words_BE 0 float 15 I 64 64 double 15 I 64 64 long double 18 I 80 128 TF 33 I 128 128
Ignore unrecognized validity, warning, and style switches that appear after this switch is given. This may be useful when compiling sources developed on a later version of the compiler with an earlier version. Of course the earlier version must support this switch.
Check that all actual parameters of a subprogram call are valid according to the rules of validity checking (Validity Checking).
Ignore all STYLE_CHECKS pragmas. Full legality checks are still carried out, but the pragmas have no effect on what style checks are active. This allows all style checking options to be controlled from the command line.
Full dynamic elaboration checks.
Full errors. Multiple errors per line, all undefined references, do not attempt to suppress cascaded errors.
Externals names are folded to all uppercase.
Internal GNAT implementation mode. This should not be used for applications
programs, it is intended only for use by the compiler and its run-time
library. For documentation, see the GNAT sources. Note that
-gnatyg so that all standard
warnings and all standard style options are turned on. All warnings and style
messages are treated as errors.
List generated expanded code in source form.
Output usage information. The output is written to
Legacy elaboration-checking mode enabled. When this switch is in effect, the pre-18.x access-before-elaboration model becomes the de facto model.
Identifier character set (
c = 1/2/3/4/8/9/p/f/n/w).
For details of the possible selections for
see Character Set Control.
Ignore representation clauses. When this switch is used, representation clauses are treated as comments. This is useful when initially porting code where you want to ignore rep clause problems, and also for compiling foreign code (particularly for use with ASIS). The representation clauses that are ignored are: enumeration_representation_clause, record_representation_clause, and attribute_definition_clause for the following attributes: Address, Alignment, Bit_Order, Component_Size, Machine_Radix, Object_Size, Scalar_Storage_Order, Size, Small, Stream_Size, and Value_Size. Pragma Default_Scalar_Storage_Order is also ignored. Note that this option should be used only for compiling – the code is likely to malfunction at run time.
Note that when
-gnatct is used to generate trees for input
into ASIS tools, these representation clauses are removed
from the tree and ignored. This means that the tool will not see them.
Reformat error messages to fit on
nn character lines
Permissive elaboration-checking mode enabled. When this switch is in effect, the post-18.x access-before-elaboration model ignores potential issues with:
and does not emit compile-time diagnostics or run-time checks.
Limit file names to
n (1-999) characters (
k = krunch).
Output full source listing with embedded error messages.
Used in conjunction with -gnatG or -gnatD to intersperse original source lines (as comment lines with line numbers) in the expanded source output.
Limit number of detected error or warning messages to
n is in the range 1..999999. The default setting if
no switch is given is 9999. If the number of warnings reaches this
limit, then a message is output and further warnings are suppressed,
but the compilation is continued. If the number of error messages
reaches this limit, then a message is output and the compilation
is abandoned. The equal sign here is optional. A value of zero
means that no limit applies.
Activate inlining across units for subprograms for which pragma
is specified. This inlining is performed by the GCC back-end. An optional
digit sets the inlining level: 1 for moderate inlining across units
or 2 for full inlining across units. If no inlining level is specified,
the compiler will pick it based on the optimization level.
Activate front end inlining for subprograms for which
Inline is specified. This inlining is performed
by the front end and will be visible in the
When using a gcc-based back end (in practice this means using any version
of GNAT other than the JGNAT, .NET or GNAAMP versions), then the use of
-gnatN is deprecated, and the use of
-gnatn is preferred.
Historically front end inlining was more extensive than the gcc back end
inlining, but that is no longer the case.
Suppresses overflow checking. This causes the behavior of the compiler to
match the default for older versions where overflow checking was suppressed
by default. This is equivalent to having
pragma Suppress (Overflow_Check) in a configuration pragma file.
Set default mode for handling generation of code to avoid intermediate
arithmetic overflow. Here
?? is two digits, a
single digit, or nothing. Each digit is one of the digits
|`1'||All intermediate overflows checked against base type (|
|`2'||Minimize intermediate overflows (|
|`3'||Eliminate intermediate overflows (|
If only one digit appears, then it applies to all cases; if two digits are given, then the first applies outside assertions, pre/postconditions, and type invariants, and the second applies within assertions, pre/postconditions, and type invariants.
If no digits follow the
-gnato, then it is equivalent to
causing all intermediate overflows to be handled in strict
This switch also causes arithmetic overflow checking to be performed
pragma Unsuppress (Overflow_Check) had been specified).
The default if no option
-gnato is given is that overflow handling
STRICT mode (computations done using the base type), and that
overflow checking is enabled.
Note that division by zero is a separate check that is not controlled by this switch (divide-by-zero checking is on by default).
See also Specifying the Desired Mode.
Suppress all checks. See Run-Time Checks for details. This switch
has no effect if cancelled by a subsequent
Cancel effect of previous
Enable polling. This is required on some systems (notably Windows NT) to
obtain asynchronous abort and asynchronous transfer of control capability.
Pragma_Polling in the GNAT_Reference_Manual for full
Don’t quit. Try semantics, even if parse errors.
Don’t quit. Generate
ALI and tree files even if illegalities.
Note that code generation is still suppressed in the presence of any
errors, so even with
-gnatQ no object file is generated.
Treat pragma Restrictions as Restriction_Warnings.
Output representation information for declared types, objects and
subprograms. Note that this switch is not allowed if a previous
-gnatD switch has been given, since these two switches
are not compatible.
Syntax check only.
Print package Standard.
Generate tree output file.
All compiler tables start at
nnn times usual starting size.
List units for this compilation.
Tag all error messages with the unique string ’error:’
Verbose mode. Full error output with source lines to
Control level of validity checking (Validity Checking).
Warning mode where
xxx is a string of option letters that denotes
the exact warnings that
are enabled or disabled (Warning Message Control).
Wide character encoding method
Suppress generation of cross-reference information.
Enable GNAT implementation extensions and latest Ada version.
Enable built-in style checks (Style Checking).
Distribution stub generation and compilation
m=r/c for receiver/caller stubs).
Direct GNAT to search the
dir directory for source files needed by
the current compilation
(see Search Paths and the Run-Time Library (RTL)).
Except for the source file named in the command line, do not look for source files in the directory containing the source file named in the command line (see Search Paths and the Run-Time Library (RTL)).
This switch is used in
gcc 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.
Inhibit the search of the default location for the GNAT Run Time Library (RTL) source files.
Inhibit the search of the default location for the GNAT Run Time Library (RTL) ALI files.
n controls the optimization level:
|`0'||No optimization, the default setting if no |
|`1'||Normal optimization, the default if you specify |
|`2'||Extensive optimization, may improve execution time, possibly at the cost of substantially increased compilation time.|
|`3'||Same as |
|`s'||Optimize space usage|
See also Optimization Levels.
Catch exit codes from the compiler and use the most meaningful as exit status.
Specifies the default location of the run-time library. Same meaning as the
gnatmake flag (Switches for gnatmake).
Used in place of
cause the assembler source file to be
.s as the extension,
instead of the object file.
This may be useful if you need to examine the generated assembly code.
Used in conjunction with
to cause the generated assembly code file to be annotated with variable
names, making it significantly easier to follow.
Show commands generated by the
gcc driver. Normally used only for
debugging purposes or if you need to be sure what version of the
compiler you are executing.
ver version of the compiler. This is the
version, not the GNAT version.
Turn off warnings generated by the back end of the compiler. Use of
this switch also causes the default for front end warnings to be set
to suppress (as though
-gnatws had appeared at the start of
You may combine a sequence of GNAT switches into a single switch. For example, the combined switch
is equivalent to specifying the following sequence of switches:
-gnato -gnatf -gnati3
The following restrictions apply to the combination of switches in this manner:
-gnatcif combined with other switches must come first in the string.
-gnatsif combined with other switches must come first in the string.
-gnatzrmay not be combined with any other switches, and only one of them may appear in the command line.
-gnat-pmay not be combined with any other switch.
-gnatyswitch), then all further characters in the switch are interpreted as style modifiers (see description of
-gnatdswitch), then all further characters in the switch are interpreted as debug flags (see description of
-gnatwswitch), then all further characters in the switch are interpreted as warning mode modifiers (see description of
-gnatVswitch), then all further characters in the switch are interpreted as validity checking options (Validity Checking).