The form of the gnatlink command is
$ gnatlink [switches] mainprog[.ali] [non-Ada objects] [linker options]
The arguments of gnatlink (switches, main ALI file, non-Ada objects or linker options) may be in any order, provided that no non-Ada object may be mistaken for a main ALI file. Any file name F without the .ali extension will be taken as the main ALI file if a file exists whose name is the concatenation of F and .ali.
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.adb 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 other than the gnatlink switches and the main
ALI file 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
Import pragmas in any Ada units.
linker options is an optional list of linker specific switches. The default linker called by gnatlink is gcc which in turn calls the appropriate system linker. Standard options for the linker such as -lmy_lib or -Ldir can be added as is. For options that are not recognized by gcc as linker options, use the gcc switches -Xlinker or -Wl,. Refer to the GCC documentation for details. Here is an example showing how to generate a linker map:
$ gnatlink my_prog -Wl,-Map,MAPFILE
Using linker options it is possible to set the program stack and heap size. See Setting Stack Size from gnatlink and Setting Heap Size from gnatlink.
gnatlink determines the list of objects required by the Ada
program and prepends them to the list of objects passed to the linker.
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.