gnat
Compile Ada source code
SYNOPSIS
gnat [options] ada_file
PARAMETERS
-c
Compile only, produce object file
-gnatA
Dynamic elaboration checks
-gnata
Enable assertions
-gnatb
Generate brief messages
-gnatc
Check syntax and semantics only
-gnatd.A
Dump tree for aspect A
-gnatE
Dynamic elaboration checking
-gnatf
Full error messages
-gnatg
Enable validity checks
-gnati.n
Max line length (1-32766)
-gnatj.nn
Max number of threads
-gnatl
Output full source
-gnatm.args
Pass args to gnatmake
-gnato
Enable inlining
-gnatp
Suppress all checks
-gnatr
Treat restrictions as violations
-gnats
Syntax check only
-gnatt
Generate Time Stamp
-gnatu
List units for compilation
-gnatv
Verbose mode
-gnatwa
Wide warning mode (most warnings)
-gnatx
Compiler exit code 0 even with errors
-gnatyN
Style checks (various rules)
-I
Search directory for sources
-O[0-3]
Optimization level
-g
Debug information
DESCRIPTION
The gnat command serves as the front-end driver for the GNAT Ada compiler, part of the GNU Ada Translator suite. It compiles Ada source files (typically .adb for bodies and .ads for specs) into object files (.o) and Ada Library Information (.ali) files, performing lexical analysis, parsing, semantic checks, and code generation via the GCC back-end.
GNAT fully implements Ada standards from Ada 83 through Ada 2022, with extensions for high-integrity systems, real-time, and safety-critical applications. Common use cases include single-file compilation or as a building block for tools like gnatmake. Options control optimization levels, debugging info, warning verbosity, style checks, and runtime behaviors like tasking or exceptions.
For example, gnat -c main.adb compiles without linking. It supports project files indirectly via GPR tools but excels in command-line workflows. Widely used in aerospace, defense, and embedded systems due to Ada's reliability features.
CAVEATS
For multi-file projects, prefer gnatmake or gprbuild as gnat handles single files best. Many options inherited from GCC; check gcc(1) man page. Deprecated in newer GNAT Pro for GPR-based builds.
BASIC EXAMPLE
gnat -gnatwa -O2 -c main.adb
Compiles main.adb with warnings, optimization, no linking.
gnatlink main.o
Links object to executable.
VERSION CHECK
gnat --version
Displays GNAT and GCC versions.
HISTORY
Developed in 1992 at NYU under DoD contract; released to FSF in 1995 as free software. Evolved with Ada standards; maintained by AdaCore since 1999. Integral to Debian/Ubuntu gnat package.


