Next: , Previous: The Definition File, Up: Creating an Import Library


H.8.2.2 GNAT-Style Import Library

To create a static import library from API.dll with the GNAT tools you should proceed as follows:

  1. Create the definition file API.def (see The Definition File). For that use the dll2def tool as follows:
              $ dll2def API.dll > API.def
    

    dll2def is a very simple tool: it takes as input a DLL and prints to standard output the list of entry points in the DLL. Note that if some routines in the DLL have the Stdcall convention (see Windows Calling Conventions) with stripped @nn suffix then you'll have to edit api.def to add it, and specify -k to gnatdll when creating the import library.

    Here are some hints to find the right @nn suffix.

    1. If you have the Microsoft import library (.lib), it is possible to get the right symbols by using Microsoft dumpbin tool (see the corresponding Microsoft documentation for further details).
                     $ dumpbin /exports api.lib
      
    2. 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.
  2. Build the import library libAPI.dll.a, using gnatdll (see Using gnatdll) as follows:
              $ gnatdll -e API.def -d API.dll
    

    gnatdll takes as input a definition file API.def and 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 -e could have been removed because the name of the definition file (before the “.def” suffix) is the same as the name of the DLL (see Using gnatdll for more information about gnatdll).