使用mingw的MSVC ++ .lib文件。名称调整 [英] Using MSVC++ .lib files with mingw. Name mangling

查看:363
本文介绍了使用mingw的MSVC ++ .lib文件。名称调整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有静态C ++库,用MSVC和dll文件(库称为opennurbs)编译。我需要在项目中使用这个库,编译通过mingw(我使用Qt创建者,但项目不使用qt库)。所以,我有未解决的外部。我想问题名称mangling。
我怎么能把.lib文件转换成.a库?
我尝试使用nm命令,但它不工作:没有符号foo.dll。
ExternC不工作,因为它是C ++库。

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.

推荐答案

一般来说,能够使用由一个编译器构建的C ++ DLL,该程序是用另一个编译器编译的。名称调整只是其中的一个问题 - 没有兼容性保证的异常处理,RTTI,内存管理甚至类布局本身(特别是对于多个和虚拟继承),只列出一些潜在的问题。

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):


  • 最好的解决方案是,原始问题完全,并获得二进制为您的编译器或从源代码构建(即在你的情况下从MinGW构建DLL和其客户端)。

  • 如果你可以暴露DLL的接口为纯C API,做它。例如。

  • 如果你想为你的DLL面向对象的API,不需要可移植性并准备投入必要的开发工作,提供COM API可能值得一看。

这篇关于使用mingw的MSVC ++ .lib文件。名称调整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆