Revision of CreateImportLibraries from 2010, January 4 - 17:17

Printer-friendly version
  • strict warning: Non-static method Text_Wiki::singleton() should not be called statically in /var/www/drupal/6.x/sites/ on line 475.
  • strict warning: Non-static method Text_Wiki::factory() should not be called statically in /usr/share/php/Text/Wiki.php on line 448.
  • strict warning: Non-static method Text_Wiki::isError() should not be called statically in /usr/share/php/Text/Wiki.php on line 449.
  • strict warning: Declaration of Text_Wiki_Parse_Emphasis::process() should be compatible with Text_Wiki_Parse::process(&$matches) in /usr/share/php/Text/Wiki/Parse/Mediawiki/Emphasis.php on line 0.

Usually (read: for all DLLs created with MinGW and also a few others) MinGW links fine against a DLL. No import library is necessary (see sampleDLL).

However there are situations when it won't. Then one needs a so-called import library to help the linker. The rest of this page gives hints as to how to create such import libraries when there is only the DLL available.

MinGW comes with a handy tool which does most of the work for you:

dlltool.exe (or i586-mingw32-dlltool or something similar). Issue 'dlltool --help' to get a brief description of the available options.

Sometimes dlltool can create an import library from the DLL. But then you wouldn't need an import library since the linker wouldn't need one. So you probably are reading this because you've got a DLL against which MinGW can't link without further help. You will provide this help by creating a def-File. There are several ways to create such a file. In the following some of these will be described:

issue 'dlltool -z somedll.def --export-all-symbol somedll.dll' (without 's)

chances are high that you'll get something like 'dlltool: somedll.dll: no symbols'. However, the resulting def-File is a good startingpoint and probably will need only little additional tweaking.

use your favorite texteditor and create a file somedll.def with the following lines:

<list of external names, one per line>

Here <list of external names> is at least the list of unsatisfied external references the linker did complain about and that are supposed to be in somedll.dll. The list is given one name per line.
Once you've created the def-File (see above) you'll issue

    dlltool -d somedll.def -l libsomedll.a

Depending on the DLL you may want to try one or more of the following:

add option -U

This will prefix all symbols in the import library with an underscore '_'

add option -k

This removes @<n> from the exported names but their calling convention remains stdcall.

add option -A

This adds an alias for all stdcall entries but without the @<n>, i.e. you get both the undecorated names (as with -k) and the decorated names.

For a detailed description of these options and dlltool take a look at the corresponding documentation.

That's it. The resulting file libsomedll.a should satisfy the linker.

Some Examples

def-file for an external lib created with Delphi

LIBRARY Diverg01.dll

Excerpt from a def-file for IBM's db2cli.dll


Note that you can also use the pexports command to help (see the Python example in the FAQ).

This wiki is not a forum for discussion of usage issues. Please use the list instead. We do not allow creation of comments by anonymous or untrusted users, on any page.
Site Status

Site maintenance performed successfully, site online Dec 13th 12:00 AM Eastern.