Is there a tool that can convert a Visual Studio object file to GCC format?

旧巷老猫 提交于 2019-12-24 03:28:03

问题


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?


回答1:


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.

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

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.




回答2:


In addition to the possible symbol differences between VC++ and GCC/G++, what's you are trying to do may be impossible due to Windows API issue.

Programs that built from Interix GCC can only work with Interix, and since Interix is a separated subsystem in parallel of the Windows subsystem (or say Win32 subsystem), you can't call any Windows API (ex. from kernel32.dll) from Interix programs.

If that licensing object file contain any Windows API calls, linking will not be possible.



来源:https://stackoverflow.com/questions/15693427/is-there-a-tool-that-can-convert-a-visual-studio-object-file-to-gcc-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!