开发者

Using MinGW built dll in a Visual Studio 2010 C++ project

I have build a dll and now I want to use this dll in a Microsoft Visual Studio project.

g++ -O0 -Wall -c -fmessage-length=0 -osrc\MyLib.o ..\src\MyLib.cpp
g++ -shared -Wl,--out-implib=MyLib.lib -Wl,--output-def=MyLib.def -oMyLib.dll src\MyLib.o -lwsock32

The dll works fine when I use it in a "gcc project".

I have tried different methodes to create the ".lib" and ".def" files and tr开发者_JAVA技巧ied to import these libs in VS by following different tutorials. But VS does not find the methodes declared in the dll...

I'm thankfull for any help.


Have you heard about name mangling? Unless the functions exported from DLL are marked as extern "C" their names are going to be mangled in a compiler-specific way. Thus the problem.


If you want your dll to be used with another compiler you have the following options:

  1. Expose only "C" interface (with extern "C") - no classes or anyting C++ specific.
  2. Make a COM dll.
  3. Make your on COM-like model that follows the same constraints.


For the benefit of others. Have a look at Binary Compatible C++ Interfaces. Its clear from the above that there is no way direct to interface C++ DLL built with MinGW with MS Visual Studio. This interfacing "works" cleanly only via C based interface.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜