Next: , Previous: Compiling Programs, Up: Compiling Using gcc

3.2 Switches for gcc

The gcc command accepts switches that control the compilation process. These switches are fully described in this section. First we briefly list all the switches, in alphabetical order, then we describe the switches in more detail in functionally grouped sections.

More switches exist for GCC than those documented here, especially for specific targets. However, their use is not recommended as they may change code generation in ways that are incompatible with the Ada run-time library, or can cause inconsistencies between compilation units.

-b target
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) from dir instead of the default location. Only use this switch when multiple versions of the GNAT compiler are available. See Options for Directory Search, for further details. You would normally use the -b or -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 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 and gcc cannot be used to run the GNAT binder.

Suppresses all inlining, even if other optimization or inlining switches are set. This includes suppression of inlining that results from the use of the pragma Inline_Always. Any occurrences of pragma Inline or Inline_Always are ignored, and -gnatn and -gnatN have no effect if this switch is present.
Suppresses automatic inlining of subprograms, which is enabled if -O3 is used.
Suppresses automatic inlining of small subprograms, which is enabled if -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 enabled if -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.
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.
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 stack-usage per-node information.
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.
Enforce Ada 83 restrictions.
Enforce Ada 95 restrictions.
Allow full Ada 2005 features.
Allow full Ada 2005 features (same as -gnat05)

Allow full Ada 2012 features (same as -gnat12)
Assertions enabled. Pragma Assert and pragma Debug to be activated. Note that these pragmas can also be controlled using the configuration pragmas Assertion_Policy and Debug_Policy. It also activates pragmas Check, Precondition, and Postcondition. Note that these pragmas can also be controlled using the configuration pragma Check_Policy.
Avoid processing 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 (see Validity Checking).
Check syntax and semantics only (no code generation attempted).
Generate CodePeer information (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 the -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 users guide.
Create expanded source files for source level debugging. This switch also suppress generation of cross-reference information (see -gnatx).
Specify a configuration pragma file (the equal sign is optional) (see The Configuration Pragmas Files).
Defines a symbol, associated with value, for preprocessing. (see Integrated 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.
Save result of preprocessing in a text file.
Indicates that the source is a multi-unit source and that the index of the unit to compile is nnn. nnn needs to be a positive number and need to be a valid index in the multi-unit source.
Specify a mapping file (the equal sign is optional) (see Units to Sources Mapping Files).
Specify a preprocessing data file (the equal sign is optional) (see 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.
Generate SCO (Source Coverage Obligation) information in the ALI file. This information is used by advanced coverage tools. See unit SCOs in the compiler sources for details in files and scos.adb.
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 -gnatg implies -gnatwae and -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 stdout.
Identifier character set (c=1/2/3/4/8/9/p/f/n/w). For details of the possible selections for c, 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, Size, Small, Stream_Size, and Value_Size. Note that this option should be used only for compiling – the code is likely to malfunction at run time.
Reformat error messages to fit on nn character lines
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 where 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 for subprograms for which pragma Inline is specified. This inlining is performed by the GCC back-end.
Activate front end inlining for subprograms for which pragma Inline is specified. This inlining is performed by the front end and will be visible in the -gnatG output.

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.

Enable numeric overflow checking (which is not normally enabled by default). Note that division by zero is a separate check that is not controlled by this switch (division by zero checking is on by default).
Suppress all checks. See Run-Time Checks for details. This switch has no effect if cancelled by a subsequent -gnat-p switch.
Cancel effect of previous -gnatp switch.
Enable polling. This is required on some systems (notably Windows NT) to obtain asynchronous abort and asynchronous transfer of control capability. See Pragma Polling, for full details.
Don't quit. Try semantics, even if parse errors.
Don't quit. Generate ALI and tree files even if illegalities.
Treat pragma Restrictions as Restriction_Warnings.
Output representation information for declared types and objects.
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 stdout.
Control level of validity checking (see Validity Checking).
Warning mode where xxx is a string of option letters that denotes the exact warnings that are enabled or disabled (see Warning Message Control).
Wide character encoding method (e=n/h/u/s/e/8).
Suppress generation of cross-reference information.
Enable GNAT implementation extensions and latest Ada version.
Enable built-in style checks (see 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 standard gcc switch causes the compiler to use larger offsets in its jump table representation for case statements. This may result in less efficient code, but is sometimes necessary (for example on HP-UX targets) in order to compile large and/or nested case statements.
-o file
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.
n = 0
No optimization, the default setting if no -O appears
n = 1
Normal optimization, the default if you specify -O without an operand. A good compromise between code quality and compilation time.
n = 2
Extensive optimization, may improve execution time, possibly at the cost of substantially increased compilation time.
n = 3
Same as -O2, and also includes inline expansion for small subprograms in the same unit.
n = 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 runtime library. Same meaning as the equivalent gnatmake flag (see Switches for gnatmake).
Used in place of -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.
Used in conjunction with -S 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.
-V ver
Execute ver version of the compiler. This is the gcc 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 the options).

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: