How can an MSVC program call an MinGW DLL?
来源:互联网 发布:淘宝网广场舞服装店 编辑:程序博客网 时间:2024/06/02 22:16
MSVC and MinGW DLL Interlinking FAQ
Q. How can an MSVC program call an MinGW DLL, and vice versa?
A. 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 (in newer MinGW versions; MinGW GCC 2.95.2 is reported not to work). 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 (the original site is unavailable now, but you may download here a version enhanced by José Fonseca):
reimp testdll.lib
gcc -o testmain testmain.c -L. -ltestdll
However, the above method does not work with __stdcall functions. 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 (downloadable here if not found elsewhere) 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. And that is the end of this FAQ.
- How can an MSVC program call an MinGW DLL?
- MSVC 和 MinGW DLL call each other
- mingw dll msvc
- mingw dll msvc
- how can you see if an application program offers a function module exit
- [转]How to load an AutoLISP program
- msvc and mingw call eachother
- How can i style an Android Switch?
- How can I style an Android Switch?
- 关于DLL,MSVC和Mingw
- How to run an ajax call after another ajax call?
- How to create an installer for your Python program
- How to compile a TCL script into an EXE program
- How to Add An Automatically Executable Program in YOCTO?
- How to call an external C function from within Oracle
- How to call different methods as given in an array
- Execute an external program
- MSVC和MinGW的DLL工具
- [httpd.conf]apache限制IP的并发数以及限制带宽的设置
- Microsoft .NET Remoting : 技术概述
- JBPM 3.1.4的J2EE应用整合初探
- 在.NET 3.5 平台上使用LINQ to SQL创建三层/多层Web应用系统(二)
- 第三名是最危险的名次
- How can an MSVC program call an MinGW DLL?
- 项目管理--关键链方法
- HDOJ2177 取(2堆)石子游戏
- [httpd.conf]Apache发布的网站限制某些网段的访问方法
- 2009.9
- 如何设置Select下拉框、CheckBox、Radio的ReadOnly属性?
- 如何使用C#内嵌脚本(一)
- 获取Ant使用的jdk,java版本
- BREW究竟是什么-BREW本质之我见