This section explains how to build DLLs using the GNAT built-in DLL support. With the following procedure, it is straightforward to build and use DLLs with GNAT.
gnatmake
tool.
gcc
-shared
and
-shared-libgcc
switches. It’s quite simple to use this method:
$ gcc -shared -shared-libgcc -o api.dll obj1.o obj2.o ...
It’s important to note that in this case all symbols found in the
object files are automatically exported. You can restrict
the set of symbols to export by passing to gcc
a definition
file (see The Definition File).
For example:
$ gcc -shared -shared-libgcc -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 requires one. Elaboration procedures are named using the package name followed by “_E”.
.ali
set with read-only attribute. This is very
important because 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, you can use the DLL by directly linking
against it. Note that you must use the GNAT shared runtime when using
GNAT shared libraries. You do this with the -shared
binder
switch.
$ gnatmake main -Iapilib -bargs -shared -largs -Lapilib -lAPI