Next: , Up: Linking Using gnatlink

5.1 Running gnatlink

The form of the gnatlink command is

     $ gnatlink [switches] mainprog[.ali] [non-Ada objects]
           [linker options]

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 Unix 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.

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 usually called ld. 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, the gcc switches -Xlinker or -Wl, shall be used. Refer to the GCC documentation for details. Here is an example showing how to generate a linker map assuming that the underlying linker is GNU ld:

     $ gnatlink my_prog -Wl,-Map,MAPFILE

Using linker options it is possible to set the program stack and heap size. See see Setting Stack Size from gnatlink and see 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.