[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5. Linking Using gnatlink

This chapter discusses gnatlink, a utility program used to link Ada programs and build an executable file. This is a simple program that invokes the UNIX linker (via the gnatgcc 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.

5.1 Running gnatlink  
5.2 Switches for gnatlink  


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

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


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.2 Switches for gnatlink

The following switches are available with the gnatlink utility:

-A
The binder has generated code in Ada. This is the default.

-C
If instead of generating a file in Ada, the binder has generated one in C, then the linker needs to know about it. Use this switch to signal to gnatlink that the binder has generated C code rather than Ada code.

-g
The option to include debugging information causes the Ada bind file (in other words, `b~mainprog.adb') to be compiled with -g. In addition, the binder does not delete the `b~mainprog.adb', `b~mainprog.o' and `b~mainprog.ali' files. Without -g, the binder removes these files by default. The same procedure apply if a C bind file was generated using -C gnatbind option, in this case the filenames are `b_mainprog.c' and `b_mainprog.o'.

-n
Do not compile the file generated by the binder. This may be used when a link is rerun with different options, but there is no need to recompile the binder file.

-v
Causes additional information to be output, including a full list of the included object files. This switch option is most useful when you want to see what set of object files are being used in the link step.

-v -v
Very verbose mode. Requests that the compiler operate in verbose mode when it compiles the binder file, and that the system linker run in verbose mode.

-o exec-name
exec-name specifies an alternate name for the generated executable program. If this switch is omitted, the executable has the same name as the main unit. For example, gnatlink try.ali creates an executable called `try'.

-b target
Compile your program to run on target, which is the name of a system configuration. You must have a GNAT cross-compiler built if target is not the same as your host system.

-Bdir
Load compiler executables (for example, gnat1, the Ada compiler) from dir instead of the default location. Only use this switch when multiple versions of the GNAT compiler are available. See the gnatgcc manual page for further details. You would normally use the -b or -V switch instead.

--GCC=compiler_name
Program used for compiling the binder file. The default is gnatgcc'. You need to use quotes around compiler_name if compiler_name contains spaces or other separator characters. As an example --GCC="foo -x -y" will instruct gnatlink to use foo -x -y as your compiler. Note that switch -c is always inserted after your command name. Thus in the above example the compiler command that will be used by gnatlink will be foo -c -x -y.

--LINK=name
name is the name of the linker to be invoked. This is especially useful in mixed language programs since languages such as c++ require their own linker to be used. When this switch is omitted, the default name for the linker is (`gnatgcc').


[ << ] [ >> ]           [Top] [Contents] [Index] [ ? ]

This document was generated by Tom Bennet on August, 25 2000 using texi2html