This section explain how to build DLLs using the GNAT built-in DLL support. With the following procedure it is straight forward to build and use DLLs with GNAT.
The first step is to build all objects files that are to be included into the DLL. This is done by using the standard gnatmake tool.
To build the DLL you must use gcc's -shared option. It is quite simple to use this method:
$ gcc -shared -o api.dll obj1.o obj2.o ...
It is important to note that in this case all symbols found in the object files are automatically exported. It is possible to restrict the set of symbols to export by passing to gcc a definition file, see The Definition File. For example:
$ gcc -shared -o api.dll api.def obj1.o obj2.o ...
If you use a definition file you must export the elaboration procedures for every package that required one. Elaboration procedures are named using the package name followed by "_E".
For the DLL to be used by client programs the bodies must be hidden from it and the .ali set with read-only attribute. This is very important otherwise GNAT will recompile all packages and will not actually use the code in the DLL. For example:
$ mkdir apilib $ copy *.ads *.ali api.dll apilib $ attrib +R apilib\*.ali
At this point it is possible to use the DLL by directly linking against it. Note that you must use the GNAT shared runtime when using GNAT shared libraries. This is achieved by using -shared binder's option.
$ gnatmake main -Iapilib -bargs -shared -largs -Lapilib -lAPI