msys下从dll文件创建lib

1.分别进入msys环境和msvc命令控制台

2.生成.def文件

方法一:

msys环境下使用:
pexports DLL_PATH\DLL_NAME.dll > DLL_PATH\DLL_NAME.def
msys下从dll文件创建lib_第1张图片

*** 推荐使用pexports,因为它导出的def是标准的def格式,不需要做任何修改,可以直接用于生成lib,pexports可在http://sourceforge.net/projects/mingw/files/MinGW/Extension/pexports/下载。

方法二:

msvc命令控制台下使用
dumpbin /exports DLL_PATH\DLL_NAME.dll > DLL_PATH\DLL_NAME.def
msys下从dll文件创建lib_第2张图片
此文件需要手工修改成类似的格式:
msys下从dll文件创建lib_第3张图片

方法三:

使用windows程序Dependency Walker 2.2打开,选择所有函数名后用Save as
msys下从dll文件创建lib_第4张图片
msys下从dll文件创建lib_第5张图片
编辑成类似上一方法的文件格式

3.生成.lib文件

lib /def:DLL_PATH\DLL_NAME.def  /machine:i386 /OUT:DLL_PATH\DLL_NAME.lib

/machine:i386 部分必须存在,但输出格式根据你的需要自行查询帮助文档获悉。

使用reimp根据lib生成a文件

  1. reimp -d libmysql.lib
  2. dlltool -k -d libmysql.def -l libmysql.a
    3.1. dlltool –input-def libmySQL.def –dllname libmySQL.dll –output-lib libmysql.a -k
    3.2. dlltool -d libmysql.def -D libmysql.dll -l libmysql.a -k

3.1和3.2功能一样,在cmd下直接输reimp有使用帮助提示,dlltool -h,有使用帮助提示

GenerateLibFromDll:

Introduction

To avoid installing and fighting against MSYS and Cygwin, you can just extract exported symbols from libvlc.dll to generate a .lib (libvlc.lib) and link your program against it. And all of this using only with Microsoft Visual Studio Tools!
In case you don't have Visual Studio you can download the free version here Visual Studio Express.
Open a Command Prompt

It can be found within the Visual Studio Tools menu entry: Start / Program Files / Microsoft Visual Studio / Visual Studio Tools / Visual Studio Command Prompt.

Extract Symbols

Within the command prompt type:
dumpbin /exports “C:\Program Files\VideoLAN\VLC\libvlc.dll” > “C:\Program Files\VideoLAN\VLC\libvlc.def”
Edit the libvlc.def file and modify it to get something like this:
EXPORTS
libvlc_add_intf
libvlc_audio_get_channel
libvlc_audio_get_mute
libvlc_audio_get_track
libvlc_audio_get_track_count
libvlc_audio_get_track_description
libvlc_audio_get_volume

Alternatively, the following command will automatically generate the DEF file:
echo EXPORTS > libvlc.def
for /f “usebackq tokens=4,* delims= " %i in (dumpbin /exports "c:\Program Files\VideoLan\VLC\libvlc.dll") do if %i==libvlc echo %i%j » libvlc.def

Generate the .lib

Still within the command prompt type:
lib /def:“C:\Program Files\VideoLAN\VLC\libvlc.def” /out:“C:\Program Files\VideoLAN\VLC\libvlc.lib” /machine:x86
Of course, you'll need to adapt the path according to your configuration.
Et voila! You have it, now you can link against libvlc.lib in your program :-)

你可能感兴趣的:(msys下从dll文件创建lib)