How to generate an import library (LIB-file) from a DLL?

Albert picture Albert · Mar 30, 2012 · Viewed 26.6k times · Source

Is it possible to autogenerate a MSVC import library (LIB-file) from a DLL? How?

Answer

Dark Falcon picture Dark Falcon · Mar 30, 2012

You can generate a DEF file using dumpbin /exports:

dumpbin /exports sqlite3.dll > exports.txt
echo LIBRARY SQLITE3 > sqlite3.def
echo EXPORTS >> sqlite3.def
for /f "skip=19 tokens=4" %A in (exports.txt) do echo %A >> sqlite3.def

The librarian can use this DEF file to generate the LIB:

lib /def:sqlite3.def /out:sqlite3.lib /machine:x86

All of the filenames (exports.txt, sqlite3.dll, sqlite3.def, etc.) should be prepended with full paths.