I have static C++ library, compiled with MSVC and dll file (library called opennurbs). I need to use this library in project, compiled by mingw (I'm use Qt creator, but project doesn't use qt libraries). So, I've got unresolved externals. I think problem with name mangling. How can I convert .lib file to .a library? I try to use nm command but it doesn't works: "No symbols in foo.dll". Extern "C" doesn't work because it's C++ library.
2 Answers
Generally speaking, you won't be able to use a C++ DLL built with one compiler from a program built with another one. Name mangling is just one of the issues - there is no compatibility guarantee for exception handling, RTTI, memory management or even the class layout itself (especially for multiple and virtual inheritance), to name just a few potential problems.
Some suggestions (none of them ideal):
- The best solution is if you can sidestep the original problem completely and either obtain binaries for your compiler or build from source code (i.e. build both DLL and its client from MinGW in your case).
- If you can expose the DLL's interface as pure C API, do it. E.g. Win32 is "C API" and works quite well with all kinds of compilers, and not just C/C++.
- If you want "object oriented" API for your DLL, don't need portability and are prepared to invest a necessary development effort, providing a COM API might be worth a look.
It's rather difficult to understand exactly what your problem is, but one solution is obvious. The openNURBS code is freely available with a completely permissive license. You should simply download it and compile it directly in mingw.
In any case this is going to be the only viable route. C++ does not have a standard binary interface and each tool has a different binary interface. This can even differ between different versions of the same tool. What's more, the MSVC compiled library will have a dependency on a different C++ runtime library from your mingw compiled code.
So, the bottom line is that you need openNURBS compiled by your mingw compiler. But thankfully that's possible because the library is distributed as source.
ABI
ofcl
andmingw
differs. Sorry. – Lol4t0