Next: Calling Conventions, Up: Mixed Language Programming
There are two ways to build a program that contains some Ada files and some other language files depending on whether the main program is in Ada or not. If the main program is in Ada, you should proceed as follows:
gcc -c file1.c gcc -c file2.c
gnatmake -c my_main.adb
gnatbind my_main.ali
gnatlink my_main.ali file1.o file2.o
The three last steps can be grouped in a single command:
gnatmake my_main.adb -largs file1.o file2.o
If the main program is in some language other than Ada, Then you may have more than one entry point in the Ada subsystem. You must use a special option of the binder to generate callable routines to initialize and finalize the Ada units (see Binding with Non-Ada Main Programs). Calls to the initialization and finalization routines must be inserted in the main program, or some other appropriate point in the code. The call to initialize the Ada units must occur before the first Ada subprogram is called, and the call to finalize the Ada units must occur after the last Ada subprogram returns. You use the same procedure for building the program as described previously. In this case, however, the binder only places the initialization and finalization subprograms into file b~xxx.adb instead of the main program. So, if the main program is not in Ada, you should proceed as follows:
gcc -c file1.c gcc -c file2.c
gnatmake -c entry_point1.adb gnatmake -c entry_point2.adb
gnatbind -n entry_point1.ali entry_point2.ali
gnatlink entry_point2.ali file1.o file2.o