How to make a .lib file when have a .dll file and a header file
Solution 1:
You're going to need Microsoft Visual C++ 2010 Express (or any other source of MSVC command line tools), and your DLL.
Steps:
dumpbin /EXPORTS yourfile.dll > yourfile.exports
- Paste the names of the needed functions from
yourfile.exports
into a newyourfile.def
file. Add a line with the wordEXPORTS
at the top of this file. - Run the following commands from
VC\bin
directory (the one wherelib.exe
and other compile tools reside).
vcvars32.bat
lib /def:yourfile.def /out:yourfile.lib
or for x64 builds
lib /def:yourfile.def /machine:x64 /out:yourfile64.lib
You should get two files generated: yourfile.lib
and yourfile.exp
Solution 2:
You can use Digital Mars's IMPLIB tool. It can create a lib file using only the dll, without any need for a .def file.
The download link is http://ftp.digitalmars.com/bup.zip.
The command line is:
implib.exe /s mydll.lib mydll.dll
Solution 3:
There is a much simpler way to create a .def
file. Search the web for the gendef utility
(you may already have it if you have Mingw-64
). Once you have it, just go to a command line and type,
gendef myfile.dll
And it will create a myfile.def
. After that, just use lib.exe
to create the myfile.lib
file as explained by John.