c++visual-studiogcccross-compilinginterix

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


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?


Solution

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