Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
833 views
in Technique[技术] by (71.8m points)

c++ - Using MSVC++ .lib files with mingw. Name mangling

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...