Chapter 3. Linking with gnatlink

Table of Contents
3.1. Running gnatlink
3.2. Switches for gnatlink

This chapter discusses gnatlink, a utility program used to link Ada programs and build an executable file. This program is basically a simple process which invokes the linker (via the gcc command) with a correct list of object files and library references. gnatlink automatically determines the list of files and references for the Ada part of a program. It uses the binder file generated by the binder to determine this list.

3.1. Running gnatlink

The form of the gnatlink command is


prefix-gnatlink [switches] mainprog[.ali] [non-Ada objects] [gcc options]

where mainprog.ali references the ALI file of the main program. The .ali extension of this file can be omitted. From this reference, gnatlink locates the corresponding binder file b_mainprog.c and, using the information in this file along with the list of non-Ada objects and linker options, constructs a linker command file to create the executable.

The arguments following mainprog.ali are passed to the linker uninterpreted. They typically include the names of object files for units written in other languages than Ada and any library references required to resolve references in any of these foreign language units, or in pragma Import statements in any Ada units. This list may also include linker switches.

gnatlink determines the list of objects required by the Ada program and prepends them to the list of objects passed to gcc. gnatlink also gathers any arguments set by the use of pragma Linker_Options and adds them to the list of arguments presented to the linker.