3
votes

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 tried 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.

3

3 Answers

3
votes

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.

1
votes

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.
1
votes

For the benefit of others. Have a look at MinGW: Mixing Compilers and 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.