Skip to content

Instantly share code, notes, and snippets.

@gavxin
Created June 10, 2015 04:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gavxin/ed518df3fe4e36dc0e63 to your computer and use it in GitHub Desktop.
Save gavxin/ed518df3fe4e36dc0e63 to your computer and use it in GitHub Desktop.
Generate import library file from dll
REM
REM Generate import library file from dll
REM
REM based on http://stackoverflow.com/questions/9946322/how-to-generate-an-import-library-lib-file-from-a-dll
REM
REM Please run in VS Command Prompt. needs dumpbin.exe and lib.exe.
@echo off
if "%~1"=="" goto usage
if "%~2"=="" goto usage
dumpbin /exports %~1 > %~n1_exports.txt
IF %ERRORLEVEL% GEQ 1 EXIT /B 2
REM Generate def file.
echo LIBRARY %~n1 > %~n1.def
echo EXPORTS >> %~n1.def
for /f "skip=19 tokens=4" %%A in ( %~n1_exports.txt ) do echo %%A >> %~n1.def
REM Generate lib
lib /def:%~n1.def /out:%~n1.lib /machine:%~2
del %~n1_exports.txt
del %~n1.def
del %~n1.exp
EXIT /B 0
:usage
echo usage: %0 [dll_file] [x64 or x86]
@gavxin
Copy link
Author

gavxin commented Jun 12, 2015

Newer version of visual studio command line prompt does not have dumpbin.exe. Please use link -dump -exports instead.

@gavxin
Copy link
Author

gavxin commented Dec 7, 2018

If this failed, manually edit the def file like.

LIBRARY xxxxx
EXPORTS
FunctionName1@4 . @1
FunctionName2@4 . @2
FunctionName3@4 . @3
FunctionName4@4 . @4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment