gnatdllbehind the Scenes
This section details the steps involved in creating a DLL.
does these steps for you. Unless you are interested in understanding what
goes on behind the scenes, you should skip this section.
We use the previous example of a DLL containing the Ada package
to illustrate the steps necessary to build a DLL. The starting point is a
set of objects that will make up the DLL and the corresponding ALI
files. In the case of this example this means that api.o and
api.ali are available. To build a relocatable DLL,
gnatdllbuilds the base file (api.base). A base file gives the information necessary to generate relocation information for the DLL.
$ gnatbind -n api $ gnatlink api -o api.jnk -mdll -Wl,--base-file,api.base
In addition to the base file, the gnatlink command generates an
output file api.jnk which can be discarded. The -mdll switch
asks gnatlink to generate the routines
DllMainCRTStartup that are called by the Windows loader when the DLL
is loaded into memory.
dlltool(see Using dlltool) to build the export table (api.exp). The export table contains the relocation information in a form which can be used during the final link to ensure that the Windows loader is able to place the DLL anywhere in memory.
$ dlltool --dllname api.dll --def api.def --base-file api.base \ --output-exp api.exp
gnatdllbuilds the base file using the new export table. Note that gnatbind must be called once again since the binder generated file has been deleted during the previous call to gnatlink.
$ gnatbind -n api $ gnatlink api -o api.jnk api.exp -mdll -Wl,--base-file,api.base
gnatdllbuilds the new export table using the new base file and generates the DLL import library libAPI.a.
$ dlltool --dllname api.dll --def api.def --base-file api.base \ --output-exp api.exp --output-lib libAPI.a
gnatdllbuilds the relocatable DLL using the final export table.
$ gnatbind -n api $ gnatlink api api.exp -o api.dll -mdll