Using MSVC ++. Lib files with mingw. Name mangling

I have a C ++ static library compiled with an MSVC and a DLL file (the library is called opennurbs). I need to use this library in a project compiled by mingw (I use Qt creator, but the project does not use qt libraries). So, I have unresolved external ones. I think the problem is with the name mangling. How can I convert a .lib file to a .a library? I try to use the nm command, but it does not work: "There are no characters in foo.dll." Extern "C" does not work because it is a C ++ library.

+4
source share
2 answers

Generally speaking, you cannot use the C ++ DLL built with one compiler from a program created with another. Name management is just one of the problems: there is no compatibility guarantee for exception handling, RTTI, memory management, and even the class layout itself (especially for multiple and virtual inheritance), to name a few potential problems.

Some suggestions (none of them are perfect):

  • The best solution is if you can completely bypass the original problem and get the binary files for your compiler or create from the source code (i.e. assemble both the DLL and its client from MinGW in your case).
  • If you can open the DLL as a pure C API, do it. For instance. Win32 is a "C API" and works great with all kinds of compilers, not just C / C ++.
  • If you need an "object-oriented" API for your DLL, you do not need portability and you are ready to invest the necessary development effort by providing a COM API, it might be worth a look.
+3
source

It’s hard to know exactly what your problem is, but one solution is obvious. openNURBS code is freely available with a fully licensed license. You just download and compile it directly in mingw.

In any case, this will be the only viable route. C ++ does not have a standard binary interface, and each tool has a different binary interface. It may even differ in different versions of the same tool. Moreover, the compiled MSVC library will have a dependency on another C ++ runtime library from the compiled mingw code.

So, in the end, you need to open openNURBS compiled by your mingw compiler. But, fortunately, this is possible because the library is distributed as a source.

+2
source

Source: https://habr.com/ru/post/1392542/


All Articles