1

I build C++ DLL using MinGW and I want to use this DLL in visual studio application. But I get Linking Error. According to http://www.mingw.org/wiki/Interoperability_of_Libraries_Created_by_Different_Compiler_Brands this URL : " DLLs that are written in C++ work too, as long as you communicate with them only through a C interface declared with extern "C". If you do otherwise, you will probably get linker errors because different compilers mangle C++ names differently. "

So the problem seems to be with different name mangling used by different compilers. Is there a way by which MinGW could use same name mangling that is used by visual studio?

RupeshMote
  • 11
  • 5
  • the problem is that they use different ABIs while they share the same file format https://en.wikipedia.org/wiki/Portable_Executable – user2485710 Jun 06 '14 at 13:30
  • why you can't build the rest of the application with MinGW ? What are you trying to accomplish ? – user2485710 Jun 06 '14 at 13:32
  • Possibly related: http://stackoverflow.com/questions/24060046/assuming-i-dont-use-any-overloaded-functions-is-there-a-way-i-can-stop-all-nam/24060249#24060249 – πάντα ῥεῖ Jun 06 '14 at 13:36
  • How the hell are you trying to link a **DLL**? You can link a `.lib` file, link an `.a` file, but all you can do with `.dll` is *load* it. In case you're trying to do so, you get certain problems with "name mangling", which differ in VS and MinGW. Use `extern "C"` construct to fix that. – polkovnikov.ph Jun 06 '14 at 18:57
  • @polkovnikov.ph: The MinGW toolchain can directly use a DLL as an import library. So at build time you can link directly to the DLL, but you still need the DLL to runt he program at runtime. I wish VS would do this - I can't think of a technical reason why it would be a problem (the MinGW guys can do it). – Michael Burr Jun 14 '14 at 22:36
  • This is a good question, but unfortunately I think the answer is a simple: no, there's no way to convince the MinGW g++ compiler to use the MSVC C++ name mangling scheme. – Michael Burr Jun 14 '14 at 22:39

1 Answers1

0

No. There is no simple way to resolve difference between the name mangeling.

You will have to stay with "C" style functions and must ensure that the calling convention is compatible. When you want to use a C++ interface you will have to use COM or implement your own (lightweight) COM replacement.

harper
  • 13,345
  • 8
  • 56
  • 105