从MinGW链接到MSVC DLL [英] Linking to MSVC DLL from MinGW

查看:1267
本文介绍了从MinGW链接到MSVC DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将LizardTech GeoExpress DSDK链接到我自己的应用程序中。我使用gcc,以便我们可以在平台上编译。在Linux和Mac上,这很容易:它们提供了一个静态库( libltidsdk.a )和标题,我们要做的就是使用它们。

I'm trying to link the LizardTech GeoExpress DSDK into my own application. I use gcc so that we can compile on for platforms. On Linux and Mac this works easily: they provide a static library (libltidsdk.a) and headers and all that we have to do is use them.

编译窗口不是那么容易。他们使用Microsoft Visual Studio构建了库,我们使用MinGW。我读过MinGW常见问题,我遇到以下问题。这个库是所有的C ++,所以我的第一个问题:这是可能的吗?

Compiling for windows isn't so easy. They've built the library using Microsoft Visual Studio, and we use MinGW. I've read the MinGW FAQ, and I'm running into the problems below. The library is all C++, so my first question: is this even possible?

只是链接对dll提供产生未定义的引用错误所有的C ++调用(构造函数,结构函数,方法等)。

Just linking against the dll as provided yields "undefined reference" errors for all of the C++ calls (constructors, desctructors, methods, etc).

基于MinGW Wiki:
http://www.mingw.org/wiki/MSVC%5Fand%5FMinGW%5FDLLs
我应该能够使用实用程序 reimp 将.lib转换为可用的东西。我试过所有的LizardTech提供的.lib文件,他们都给无效或损坏的导入库。我试过reimp工具的版本0.4和0.3。

Based on the MinGW Wiki: http://www.mingw.org/wiki/MSVC%5Fand%5FMinGW%5FDLLs I should be able to use the utility reimp to convert a .lib into something useable. I've tried all of the .lib files provided by LizardTech, and they all give "invalid or corrupt import library". I've tried both version 0.4 and 0.3 of the reimp utility.

使用Wiki中描述的第二种方法,我运行pexport和dlltool通过dll a .a存档,但会生成相同的未定义引用。

Using the second method described in the wiki, I've run pexport and dlltool over the dll to get a .a archive, but that produces the same undefined references.

BTW:我已阅读下面的讨论。它留下了一些歧义,是否这是可能的,并且在MinGW Wiki页面,似乎这应该是可行的。如果这是不可能的,这就是我需要知道的。如果可以,我想知道如何才能让这种情况发生。

BTW: I have read the discussion below. It left some ambiguity as to whether this is possible, and given the MinGW Wiki page it seems like this should be doable. If it is impossible, that's all I need to know. If it can be done, I'd like to know how I can get this to happen.

如何链接到VS2008从g ++生成的.libs

谢谢!

推荐答案

您不能这样做。他们从他们的dll而不是C函数导出C ++类。区别在于,c ++函数总是以特定于特定版本编译器的破坏形式导出。

You can't do this. They have exported C++ classes from their dll, rather than C-functions. The difference is, c++ functions are always exported with names in a mangled form that is specific to a particular version of the compiler.

它们的dll只能在msvc中使用形式,并且可能不会在不同版本的msvc之间工作,因为微软以前改变了他们的修改方案。

Their dll is usable by msvc only in that form, and will probably not even work between different versions of msvc, as Microsoft have changed their mangling scheme before.

如果你有任何杠杆,你需要让他们改变他们的邪恶方式。否则你需要使用MSVC编写一个shim dll,它将导入所有的类,并通过返回接口的c函数重新导出它们。

If you have any leverage, you need to get them to change their evil ways. Otherwise you will need to use MSVC to write a shim dll, that will import all the classes, and re-export them via c functions that return interfaces.

这篇关于从MinGW链接到MSVC DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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