有一个工具,可以将Visual Studio对象文件转换为GCC格式?

问题描述:

我在Windows上使用Interix构建C ++应用程序,需要链接三个目标文件以提供第三方许可模块的功能。第三方提供了Visual Studio构建的目标文件。有没有反正转换文件与GCC一起使用?例如,如果我将名称从Visual Studio样式更改为GCC样式,这是足够的,或两个目标文件格式之间有其他差异吗?

I am building a C++ application on Windows using Interix and need to link in three object files to supply a third-party licensing module's functionality. The third party has supplied the object files as built by Visual Studio. Is there anyway to convert the files for use with GCC? For example, perhaps if I change the name mangling from Visual Studio style to GCC style that would be sufficient, or are there other differences between the two object file formats?

Windows没有标准化的C ++ ABI(应用程序二进制接口)。它有一个C ABI,但。这是由 Kernel32.DLL 使用的ABI,所以所有Windows编程环境都理解它。很多人也可以生成这样的DLL。

Windows does not have a standardized C++ ABI (Application Binary Interface). It does have a C ABI, though. This is the ABI used for instance by Kernel32.DLL, so all Windows programming environments understand it. Many can also produce such DLLs.

在这种情况下,C ++ .obj文件必须通过Visual Studio链接器链接。该链接器肯定能够创建DLL文件。您必须编写 externC函数来包装许可功能。添加 __ declspec(dllexport)以指示这些函数是从DLL导出的(在Windows上,函数默认为专用于DLL)。

In this case, the C++ .obj files have to be linked by the Visual Studio linker. That linker is definitely capable of creating DLL files. You'll have to write extern "C" functions to wrap the licensing functionality. Add __declspec(dllexport) to indicate that those functions are exported from the DLL (on Windows, functions by default are private to a DLL).

在标题中,声明与 __ declspec(dllimport)相同的函数。 GCC也理解。然后链接到新生成的DLL,这将解析 dllimport 的符号。

In a header, declare those same functions as __declspec(dllimport). GCC understands that as well. Then link against the newly produced DLL, which will resolve the dllimport'ed symbols.