Last active
July 8, 2021 12:11
-
-
Save adunstan/7bc0fcb83d60002092e66a4adec7ea35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
rem see http://stackoverflow.com/questions/9946322/how-to-generate-an-import-library-lib-file-from-a-dll#9946390 | |
rem see also http://www.postgresql-archive.org/MSVC-pl-perl-error-message-is-not-verbose-enough-td5913411.html | |
rem see also https://postgr.es/m/CABcP5fjEjgOsh097cWnQrsK9yCswo4DZxp-V47DKCH-MxY9Gig@mail.gmail.com | |
REM Usage: dll2lib [32|64] some-file.dll | |
REM | |
REM Generates some-file.lib from some-file.dll, making an intermediate | |
REM some-file.def from the results of dumpbin /exports some-file.dll. | |
REM Currently must run without path on DLL. | |
REM (Fix by removing path when of lib_name for LIBRARY line below?) | |
REM | |
REM Requires 'dumpbin' and 'lib' in PATH - run from VS developer prompt. | |
REM | |
REM Script inspired by http://stackoverflow.com/questions/9946322/how-to-generate-an-import-library-lib-file-from-a-dll | |
SETLOCAL | |
if "%1"=="32" (set machine=x86) else (set machine=x64) | |
set dll_file=%2 | |
set dll_file_no_ext=%dll_file:~0,-4% | |
set exports_file=%dll_file_no_ext%-exports.txt | |
set def_file=%dll_file_no_ext%.def | |
set lib_file=%dll_file_no_ext%.lib | |
set lib_name=%dll_file_no_ext% | |
dumpbin /exports %dll_file% > %exports_file% | |
echo LIBRARY %lib_name% > %def_file% | |
echo EXPORTS >> %def_file% | |
for /f "skip=19 tokens=1,4" %%A in (%exports_file%) do if NOT "%%B" == "" (echo %%B @%%A >> %def_file%) | |
lib /def:%def_file% /out:%lib_file% /machine:%machine% | |
REM Clean up temporary intermediate files | |
del %exports_file% %def_file% %dll_file_no_ext%.exp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What are you using it for? I haven't had to use it for quite a while.