mingw 生成.a 转为.lib

更新时间:2023-05-21 11:31:26 阅读: 评论:0

fly的第三人称单数
转:由MinGW编译出的.a生成VC下的.dll
(2013-12-01 15:42:11)
转载▼
    分类:C/C
使用MinGW编译一份库代码,可能是由于configure不好,导致只能生成.a文件,google发现一些方法,备份一下。
以下为源自blog.henix.info/blog/mingw-a-convert-dll.html的原文,感谢原作者:
最近遇到这样的问题:只有用 Cygwin 编译出来的静态库(.a),需要转换成可以在 VC++ 中调用 .dll 和 .lib 。
  网上大多说的是 dll 怎么生成 .lib 什么的,跟我要的不一样。所以我自己想了这么一种办法:
先用 ar 将 .a 中的所有 .o 文件解出来:
ar x libatlas.a
使用 MinGW 的 --export-all-symbols 选项,链接成 dll ,并导出所有符号:
gcc -shared -o atlas.dll *.o -Wl,--export-all-symbols,--output-def,atlas.def
使用 VC++ 自带的 lib 命令制作 .lib(需要上一步的 .def 文件):
lib /machine:i386 /def:atlas.def
Links:
/wiki/MSVC_and_MinGW_DLLs
以下为源自/lovesaber/archive/2012/11/27/2790297.html
一、MSVC调用MINGW生成的dll和lib
gcc -shared -o testdll.dll testdll.c-Wl,--output-def,testdll.def生成dll文件和def文件
lib /machine:i386 /def:testdll.def生成lib 文件和exp文件。(lib为MSVC的工具,可以在VS安装的bin目录下找到)
广东高考语文试题生成的dll文件和lib文件就可以被MSVC调用了。
注意:C++的dll不具有2进制级别的共享性,也就是说VC的MinGW的C++ dll不能混用。而C的dll却可以。
二、minGW调用MSVC生成的库
cl /LD testdll.c生成dll文件和lib文件
pearl
gcc - testmmain.c -ltestdll -L.编译连接生成可执行程序
hardest
PS:
奠基是什么意思以下为MinGW官网给的转换示例,备份一下。
原址:/wiki/MSVC_and_MinGW_DLLs
MSVC and MinGW DLLs
View
Revisions
miss you是什么意思Posted February 26th, 2009 by earnie
dll
mskfaq
msvc
TODO: Reformat to new wiki syntax.
!!! [Minimalist GNU for Windows | ]
!! MSVC and MinGW DLLs
Assume we have a testdll.h, testdll.c, In the first ca, we will compile testdll.c with MinGW, and let the MSVC-compiled testmain call it. You should u
gcc -shared -o testdll.dll testdll.c -Wl,--output-def,testdll.def,--out-implib,libtestdll.a
to produce the DLL and DEF files. MSVC cannot u the MinGW library, but since you have already the DEF file you may easily produce one by the Microsoft LIB tool:2014浙江高考英语
lib /machine:i386 /def:testdll.def
Once you have testdll.lib, it is trivial to produce the executable with MSVC:
cl testmain.c testdll.lib
Now for MinGW programs calling an MSVC DLL. We have two methods. One way is to specify the LIB files directly on the command line after the main program. For example, after
cl /LD testdll.c
u
gcc -o testmain testmain.c testdll.lib
伤仲永翻译The other way is to produce the .a files for GCC. For __cdecl functions (in most cas), it is simple: you only need to apply the reimp tool from Anders Norlander (since his web site is no longer available, you may choo to download
[this version|/download.asp?path=&file=reimp_new.zip]
enhanced by Jo Fonca):
reimp testdll.lib
regenerategcc -o testmain testmain.c -L. -ltestdll
However, for __stdcall functions, the above method does not work. For MSVC will prefix an underscore to __stdcall functions while MinGW will not. The right way is to produce the DEF file using the pexports tool included in the mingw-utils package and filter off the fi
rst underscore by d:
pexports testdll.dll | d "s/^_//" > testdll.def
Then, when using dlltool to produce the import library, add `-U' to the command line:
dlltool -U -d testdll.def -l libtestdll.a
And now, you can proceed in the usual way:
gcc -o testmain testmain.c -L. -ltestdll
Hooray, we got it.
This guide may also be helpful.
Here is an example of creating a .lib file from a mingw dll, in order to be able to u it from MSVC.

本文发布于:2023-05-21 11:31:26,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/116995.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:生成   文件   编译   目录   备份   进制   级别
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图