Next: Building DLLs with gnatdll, Previous: Building DLLs with GNAT Project files, Up: Mixed-Language Programming on Windows
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.
$ gcc -shared -shared-libgcc -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 -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 required one. Elaboration procedures are named using the package name followed by "_E".
$ 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