4
votes

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
You say that you have a static library and a DLL. Is that correct? That means you have two .lib files. One for the static library that contains lots of code, and one for the DLL which just has import stubs.David Heffernan
Seems, you can do noting (like me, urgh!), becuse ABI of cl and mingw differs. Sorry.Lol4t0
The binary files produced by Microsoft's compiler will not be compatible with MinGW/GCC. You'll need to recompile the library before you can link successfully.Cody Gray
I have one .lib file, called openNURBS.lib and one dll file, called openNURBS.dll. And I have visual studio project with sources. I can compile it and get static and dynamic lib. But I need to get .a lib, that I can use with mingw.flamingo

2 Answers

4
votes

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

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.