把庫檔案從msvc格式(.lib)轉化成MinGW格式(.a)的方法。
收藏
使用MinGW附帶的工具reimp.exe,該工具一般在MinGW/bin目錄下,其readme文檔在MinGW/doc/reimp目錄下,
方法很簡單,比如:
C:/CodeBlocks/MinGW/lib/dx9>reimp d3d8.lib
就會產生一個“libd3d8.a”檔案,這個檔案就可以讓基於MinGW的編譯器連結使用了。
我用這個方法成功的把DirectX9c的.lib庫轉化成了.a庫,並在CodeBlocks下編譯成功了其產生的dx項目,
但是有三個.lib檔案無法通過這個方法轉換:DxErr.lib、DxErr8.lib、DxErr9.lib,估計其他方法,
但似乎沒有他們也不影響DX9c庫的使用,先這樣,需要的話再想辦法吧。
還有一個辦法,來源是:
http://topic.csdn.net/t/20040721/11/3195357.htm
不知道是否可行,可以試試。
GCC和VC都使用COFF格式,所以VC中的.obj .lib與gcc用的.o
.a是一樣的(在WINDOWS下),只是副檔名不一樣,通常你只要改一下名稱就OK啦!不過有些庫不行,因為庫中的代碼可能會用到一些編譯器專有的特
性,用VC做的.lib可能在gcc下沒法通過編譯(缺少符號),反之亦然。
reimp的readme文檔內容如下:
README for reimp
================
* Overview
`reimp' is a tool to convert Microsoft's new-style (short) import
libraries to import libraries for win32 ports of GNU tools (mingw32,
cygwin).
`reimp' reads an MS import library and writes all imports to the
corresponding .DEF file(s) that it feeds to `dlltool' that creates the
import library.
* Invocation
Usage: reimp [options] IMPLIB
Options:
-s, --dump-symbols dump symbols to stdout
-d, --only-def only create .def files
-c, --keep-case keep case in lib*.a file names
--dlltool <name> use <name> for dlltool
--as <name> use <name> for assembler
The `--dump-symbols' option makes `reimp' use a quick method for
finding imported symbols and sending the names of found symbols to
stdout. If the input library contain non-imported symbols they will be
listed as well. The output symbols will have all decoration preserved
(i.e '_' will prefix most symbols), so if you feed it to dlltool you
should strip leading underscores. For example
echo EXPORTS > imp.def
reimp imp.lib | sed 's/_//' >> imp.def
dlltool -k --def imp.def --output-lib libimp.a --dllname imp.dll
The `--only-def' option makes `reimp' stop after generating the .DEF
file(s).
By default `reimp' converts all output library names to lower-case. By
using the `keep-case' option `reimp' will use exactly the case of the
DLL imported from when creating an import library. KERNEL32.dll will
generate libKERNEL32.a and not libkernel32.a as it would be default.
* Notes on mixed libraries
If an input library contain regular objects (non-imports, i.e code and
data) `reimp' will write out those objects unless you specify one of
the `--only-def' and `--dump-symbols' options. You probably want to
include those objects as well in the generated library. `reimp'
doesn't do that automatically so you have to do it manually using
`ar', like this
reimp imp.lib # this generates several .o or .obj files.
ar rcs libimp.a *.obj # add them to library
* Contact information
URL: http://www.acc.umu.se/~anorland/gnu-win32/
Anders Norlander <anorland@hem2.passagen.se
>