从MinGW .a转换为VC ++ .lib [英] Convert from MinGW .a to VC++ .lib

查看:180
本文介绍了从MinGW .a转换为VC ++ .lib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个旧库(C ++),只能在Windows的MinGW + MSYS32上构建.由此,我可以生成一个从GNU libtool生成的.a静态库文件.我的主要开发工作是在Visual Studio 2008中完成的.如果我尝试使用MinGW生产的库并将其链接到Visual Studio中,它将抱怨缺少外部组件.这很可能是由于完成了C ++符号修饰,并且它与.a文件中的内容不匹配.有什么已知的方法可以将静态.a文件转换为VC ++库格式?

I have an old library (in C++) that I'm only able to build on MinGW+MSYS32 on Windows. From that I can produce a .a static library file generated from GNU libtool. My primary development is done in Visual Studio 2008. If I try to take the MinGW produced library and link it in Visual Studio, it complains about missing externals. This is most likely due to the C++ symbol mangling that is done, and that it doesn't match whats in the .a file. Is there any know way to convert a static .a file to VC++ library format?

推荐答案

如果符号的处理方式不同,则编译器将使用不同的ABI,并且您将无法转换"或编译任何库:原因名称有意避免使用不同的方式对其进行修改,以避免用户成功使用不同的ABI从目标文件构建可执行文件. ABI定义了如何传递参数,如何表示虚拟功能表,如何引发异常,基本数据类型的大小以及许多其他事情.名称修改也是其中的一部分,并且经过精心选择,以使其高效且与同一平台上的其他ABI不同.查看名称修改是否确实不同的最简单方法是使用两个编译器仅使用基本类型来编译具有几个函数的文件,并查看符号(在UNIX上,我会使用nm;我是我不是Windows程序员,因此我不知道在那里使用什么工具.

If symbols are mangled differently, the compilers are using a different ABI and you won't be able to "convert" or whatever the compiled libraries: the reason names are mangled in different ways is intentional to avoid users from ever succeeding with building an executable from object files using different ABIs. The ABI defines how arguments are passed, how virtual function tables are represented, how exceptions are thrown, the size of basic data types, and quite a number of other things. The name mangling is also part of this and carefully chosen to be efficient and different from other ABIs on the same platform. The easiest way to see if the name mangling is indeed different is to compiler a file with a couple of functions using only basic types with both compilers and have a look at the symbols (on UNIX I would use nm for this; I'm not a Windows programmer and thus I don't know what tool to use there).

基于 Wikipedia ,看来MinGW还使用了不同的运行时库:布局以及MinGW( libstdc ++ )和Visual Studio( Dinkumware )不兼容.即使两个编译器之间的ABI相同,使用的标准C ++库也不相同.如果ABI相同,则需要替换设置,以使一个编译器使用相应的其他编译器的标准库.无法使用已编译的库执行此操作.我不知道这是否可行.

Based on Wikipedia it seems that MinGW also uses a different run-time library: the layout and the implementation of the standard C++ library used by MinGW (libstdc++) and Visual Studio (Dinkumware) is not compatible. Even if the ABI between the two compilers is the same, the standard C++ library used isn't. If the ABI is the same you would need to replace set things up so that one compiler uses the standard library of the respective other compiler. There is no way to do this with the already compiled library. I don't know if this is doable.

就我个人而言,我不会尝试在这两个不同的编译器之间进行链接,因为它势必根本无法正常工作.相反,您需要将实现移植到通用编译器,然后从那里进行编译.

Personally I wouldn't bother with trying to link things between these two different compiler because it is bound not to work at all. Instead, you'd need to port the implementation to a common compiler and go from there.

这篇关于从MinGW .a转换为VC ++ .lib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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