LinuxCommandLibrary

gnat

Compile Ada source code

SYNOPSIS

gnat [options] file...

PARAMETERS

-c
    Compile only; do not link the program. This generates .ali (Ada Library Information) and .o (object) files.

-o output_file
    Specify the name of the output executable file when linking.

-gnatg
    Generate debugging information, allowing the use of a debugger (like gdb) on the compiled program. Equivalent to -g.

-gnatp
    Suppress all compilation warnings.

-gnatw<category>
    Enable or disable specific categories of warnings. For example, -gnatwe enables all warnings, while -gnatws disables them.

-O<level>
    Enable optimization at a specified level (e.g., -O2, -O3). This leverages GCC's optimization passes.

-gnatV
    Produce very verbose output, including detailed Ada-specific messages and warnings generated by the compiler.

-I<dir>
    Add <dir> to the list of directories searched for Ada source files (.ads, .adb) and object files (.o).

-a<dir>
    Add <dir> to the list of directories searched for Ada library information files (.ali files).

-v
    Enable verbose operation, showing the commands executed by gnat internally (e.g., calls to as, ld).

--version
    Display the version information of the GNAT compiler and exit.

--help
    Display a summary of command-line options and exit.

DESCRIPTION

GNAT (GNU New Ada Translator) is the GNU Compiler Collection (GCC) front-end for the Ada programming language. It is a powerful, production-quality native Ada compilation system. GNAT translates Ada source code (files typically ending in .adb for bodies and .ads for specifications) into machine code, allowing developers to build executable programs. GNAT supports all versions of the Ada standard (Ada 83, Ada 95, Ada 2005, Ada 2012, and Ada 2022) and integrates seamlessly with the standard GNU toolchain, leveraging GCC's powerful optimization capabilities and multi-platform support. It's often used for embedded systems, real-time applications, and high-integrity software where Ada's strong typing, reliability features, and concurrency capabilities are highly valued.

CAVEATS

GNAT primarily handles the compilation of individual Ada source files. For managing complex Ada projects with multiple source files, dependencies, and intricate build configurations, the gprbuild project manager is the preferred and more powerful tool, which internally orchestrates calls to gnat. Users should ensure a complete GNAT toolchain is installed, as it relies on other GNU utilities like the assembler and linker.

COMPILATION WORKFLOW

When compiling Ada code, gnat processes Ada specification (.ads) and body (.adb) files. For each compiled unit, it typically generates two primary output files: an object file (.o) containing machine code and an Ada Library Information (.ali) file. The .ali file contains crucial metadata, including symbol information, dependency data, and other details necessary for separate compilation and strong type checking across compilation units. These object files are then linked, often with the Ada runtime libraries, to create the final executable program.

INTEGRATION WITH GCC

GNAT is not a standalone compiler but rather a front-end component of the GNU Compiler Collection (GCC). This means that while gnat handles the Ada-specific parsing, semantic analysis, and intermediate code generation, it leverages GCC's robust backend for code optimization, assembly generation, and target-specific machine code output. This deep integration allows GNAT to benefit from GCC's extensive support for various hardware architectures and operating systems, as well as its highly optimized code generation capabilities, resulting in efficient and portable Ada programs.

HISTORY

The GNAT project was initiated in 1992 by Ada Core Technologies (now AdaCore) and New York University as a free software compiler for Ada. Its first official release was in 1995. GNAT quickly gained significant traction and was later integrated into the GNU Compiler Collection (GCC) in 2001, solidifying its role as the primary Ada compiler for Linux and other Unix-like systems. It continues to be actively developed, keeping pace with new Ada standards and supporting a wide range of architectures and operating systems.

SEE ALSO

gprbuild(1), gcc(1), make(1), gdb(1)

Copied to clipboard