Posted February 26th, 2009 by earnie

TODO: Reformat to new wiki syntax.

!!! [Minimalist GNU for Windows | http://www.mingw.org]

!! MSVC and MinGW DLLs

Assume we have a testdll.h, testdll.c, and testmain.c. In the first case, we will compile testdll.c with MinGW, and let the MSVC-compiled testmain call it. You should use

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 use the MinGW library, but since you have already the DEF file you may easily produce one by the Microsoft LIB tool:

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

use

gcc -o testmain testmain.c testdll.lib

The other way is to produce the .a files for GCC. For __cdecl functions (in most cases), it is simple: you only need to apply the reimp tool from Anders Norlander (since his web site is no longer available, you may choose to download
[this version|http://wyw.dcweb.cn/download.asp?path=&file=reimp_new.zip]
enhanced by Jose Fonseca):

reimp testdll.lib
gcc -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 first underscore by sed:

pexports testdll.dll | sed "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 use it from MSVC.

最新文章

  1. Web 存储
  2. tiny中文乱码问题,不过仅适用于windows,所以xml不可以出现中文
  3. Android 实例子源代码文件下载地址380个合集
  4. Sublime Text 2 配置
  5. 二维码扫描利用ZBar实现
  6. 【C#学习笔记】改变颜色
  7. 自动化:Appium运行成功,取得一个小的胜利
  8. 关于duilib中的list的扩展探索
  9. MFC定时器
  10. 更新-----Scripts:执行双网卡绑定
  11. Swift - 判端网络连接状态,连接类型(3G还是Wifi)
  12. 使用beanstalkd实现定制化持续集成过程中pipeline
  13. C/C++数据在内存中的存储方式
  14. CPU与IRP的一些相关函数
  15. Java Service Wrapper--来自官网文件
  16. Talend 将Oracle中数据导入到hive中,根据系统时间设置hive分区字段
  17. linux升级php至5.6
  18. java进程和线程的区别
  19. 【转】每天一个linux命令(4):mkdir命令
  20. Oracle根据字段值找到表名和列名

热门文章

  1. 如果想使用GIT Extentions的解决冲突窗口,安装时必须勾选KDIFF3
  2. SWD Registers
  3. 对数据集“dsArea”执行查询失败。 (rsErrorExecutingCommand),Query execution failed for dataset 'dsArea'. (rsErrorExecutingCommand),Manually process the TFS data warehouse and analysis services cube
  4. idhttpserver的使用方法
  5. 【Android病毒分析报告】- 手机支付毒王“银行悍匪”的前世今生
  6. 较老版本 AFNetworking 使用心得
  7. 用ImageSwitcher实现显示图片(更改图片时有动画效果)
  8. attrs.xml中declare-styleable 详解(用于自定义控件的属性)
  9. [Web 前端] ECMAScript5之StrictMode
  10. .Net Excel操作之NPOI(一)简介