3

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?

WilliamKF
  • 41,123
  • 68
  • 193
  • 295
  • This is a very hard thing to do. – brian beuning Mar 28 '13 at 22:45
  • 2
    There are lots of differences other than just name mangling. Better forget it, you will have much more chances asking the third party either for the code so you can compile it yourself, or for GCC (MinGW?) object files. Don't forget to explicitly state your GCC/MinGW version to ensure ABI compatibility. – syam Mar 28 '13 at 22:47
  • 1
    Easiest solution would be to get Visual C++ Express Edition, and wrap the object files in a DLL with C interface. GCC on Windows understands that; the OS is provided as DLL's with a C interface after all. – MSalters Mar 29 '13 at 08:16
  • 1
    @MSalters Sounds like you have the makings of an answer there! Would you please elaborate on the details and add an answer? – WilliamKF Mar 29 '13 at 13:58

2 Answers2

4

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.

MSalters
  • 173,980
  • 10
  • 155
  • 350
  • If you go down this path you may find some of this http://stackoverflow.com/questions/2045774/developing-c-wrapper-api-for-object-oriented-c-code helpful (disclaimer - accepted answer is mine...) – Michael Anderson Apr 02 '13 at 06:47
1

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.

Low power
  • 273
  • 3
  • 7