184.108.40.206 Building DLLs with gnatdll
Note that it is preferred to use GNAT Project files
(Building DLLs with GNAT Project files) or the built-in GNAT
DLL support (Building DLLs with GNAT) or to build DLLs.
This section explains how to build DLLs containing Ada code using
gnatdll. These DLLs will be referred to as Ada DLLs in the
remainder of this section.
The steps required to build an Ada DLL that is to be used by Ada as well as
non-Ada applications are as follows:
- You need to mark each Ada `entity' exported by the DLL with a C or
Stdcall calling convention to avoid any Ada name mangling for the
entities exported by the DLL
(see Exporting Ada Entities). You can
skip this step if you plan to use the Ada DLL only from Ada applications.
- Your Ada code must export an initialization routine which calls the routine
adainit generated by `gnatbind' to perform the elaboration of
the Ada code in the DLL (Ada DLLs and Elaboration). The initialization
routine exported by the Ada DLL must be invoked by the clients of the DLL
to initialize the DLL.
- When useful, the DLL should also export a finalization routine which calls
routine adafinal generated by `gnatbind' to perform the
finalization of the Ada code in the DLL (Ada DLLs and Finalization).
The finalization routine exported by the Ada DLL must be invoked by the
clients of the DLL when the DLL services are no further needed.
- You must provide a spec for the services exported by the Ada DLL in each
of the programming languages to which you plan to make the DLL available.
- You must provide a definition file listing the exported entities
(The Definition File).
- Finally you must use gnatdll to produce the DLL and the import
library (Using gnatdll).
Note that a relocatable DLL stripped using the strip
binutils tool will not be relocatable anymore. To build a DLL without
debug information pass -largs -s to gnatdll. This
restriction does not apply to a DLL built using a Library Project.
See Library Projects.