Next: , Previous: Dynamic Allocation Control, Up: Switches for gnatbind


4.4.2.6 Binding with Non-Ada Main Programs

The description so far has assumed that the main program is in Ada, and that the task of the binder is to generate a corresponding function main that invokes this Ada main program. GNAT also supports the building of executable programs where the main program is not in Ada, but some of the called routines are written in Ada and compiled using GNAT (Mixed Language Programming). The following switch is used in this situation:

-n
No main program. The main program is not in Ada.

In this case, most of the functions of the binder are still required, but instead of generating a main program, the binder generates a file containing the following callable routines:

`adainit'
You must call this routine to initialize the Ada part of the program by calling the necessary elaboration routines. A call to adainit is required before the first call to an Ada subprogram.

Note that it is assumed that the basic execution environment must be setup to be appropriate for Ada execution at the point where the first Ada subprogram is called. In particular, if the Ada code will do any floating-point operations, then the FPU must be setup in an appropriate manner. For the case of the x86, for example, full precision mode is required. The procedure GNAT.Float_Control.Reset may be used to ensure that the FPU is in the right state.

`adafinal'
You must call this routine to perform any library-level finalization required by the Ada subprograms. A call to adafinal is required after the last call to an Ada subprogram, and before the program terminates.

If the `-n' switch is given, more than one ALI file may appear on the command line for gnatbind. The normal `closure' calculation is performed for each of the specified units. Calculating the closure means finding out the set of units involved by tracing `with' references. The reason it is necessary to be able to specify more than one ALI file is that a given program may invoke two or more quite separate groups of Ada units.

The binder takes the name of its output file from the last specified ALI file, unless overridden by the use of the `-o file'.

The output is an Ada unit in source form that can be compiled with GNAT. This compilation occurs automatically as part of the `gnatlink' processing.

Currently the GNAT run time requires a FPU using 80 bits mode precision. Under targets where this is not the default it is required to call GNAT.Float_Control.Reset before using floating point numbers (this include float computation, float input and output) in the Ada code. A side effect is that this could be the wrong mode for the foreign code where floating point computation could be broken after this call.