If a Microsoft-style import library
API.lib or a GNAT-style
libAPI.a is available
API.dll you can skip this section. You can also skip this
libAPI.dll is built with GNU tools
as in this case it is possible to link directly against the
DLL. Otherwise read on.
As previously mentioned, and unlike Unix systems, the list of symbols
that are exported from a DLL must be provided explicitly in Windows.
The main goal of a definition file is precisely that: list the symbols
exported by a DLL. A definition file (usually a file with a
suffix) has the following structure:
[LIBRARY ``name``] [DESCRIPTION ``string``] EXPORTS ``symbol1`` ``symbol2`` ...
This section, which is optional, gives the name of the DLL.
This section, which is optional, gives a description string that will be embedded in the import library.
This section gives the list of exported symbols (procedures, functions or
variables). For instance in the case of
API.def looks like:
EXPORTS some_var get
Note that you must specify the correct suffix (
(see Windows Calling Conventions) for a Stdcall
calling convention function in the exported symbols list.
There can actually be other sections in a definition file, but these sections are not relevant to the discussion at hand.
You can automatically create the definition file
(see The Definition File) from a DLL.
For that use the
dlltool program as follows:
$ dlltool API.dll -z API.def --export-all-symbols
Note that if some routines in the DLL have the
Stdcallconvention (Windows Calling Conventions) with stripped
@`nn'suffix then you’ll have to edit
api.defto add it, and specify
gnatdllwhen creating the import library.
Here are some hints to find the right
- - If you have the Microsoft import library (.lib), it is possible to get the right symbols by using Microsoft
dumpbintool (see the corresponding Microsoft documentation for further details).$ dumpbin /exports api.lib
- - If you have a message about a missing symbol at link time the compiler tells you what symbol is expected. You just have to go back to the definition file and add the right suffix.
To create a static import library from
API.dll with the GNAT tools
you should create the .def file, then use
(see Using gnatdll) as follows:
$ gnatdll -e API.def -d API.dll
gnatdlltakes as input a definition file
API.defand the name of the DLL containing the services listed in the definition file
API.dll. The name of the static import library generated is computed from the name of the definition file as follows: if the definition file name is
xyz.def, the import library name will be
libxyz.a. Note that in the previous example option
-ecould have been removed because the name of the definition file (before the
.defsuffix) is the same as the name of the DLL (Using gnatdll for more information about
A Microsoft import library is needed only if you plan to make an Ada DLL available to applications developed with Microsoft tools (Mixed-Language Programming on Windows).
To create a Microsoft-style import library for
should create the .def file, then build the actual import library using
$ lib -machine:IX86 -def:API.def -out:API.lib
If you use the above command the definition file
API.defmust contain a line giving the name of the DLL:LIBRARY "API"
See the Microsoft documentation for further details about the usage of