Search code examples
c++windowslinkermingw32binaries

C++ windows binaries: conditions to be used with MinGW


I am new to C++ and I am now struggling with compiling and linking. Recently I have been using cmake and make to recompile a library (mlpack) that makes usage of Boost (Cmake does not find boost 1.51 (windows 8)).

In a first attempt, I downloaded precompiled binaries for windows. This did not work out well and I have been explained the binaries I was using were for MSVC, not MinGW, therefore troubles. And indeed, after recompiling boost using MinGW, things went ok.

Here I would just like to get an intuition what would be the differences between binaries for MSVC and MinGW. I (naively?) thought binaries were specific to OS/processor. What do the binaries for MSVC contains that make them unusable by MinGW ?


Solution

  • It is relatively easy to combine artifacts (static/shared libraries) produced by MSVC and MinGW (this applies to other C compilers in general) as long as they export pure C API. This makes C API to be very portable and that's one of the main reasons why so many popular libraries still prefer to use pure C API.

    The story with C++ is completely different. The most notorious obstacles for proper interoperability between artifacts produced by different C++ compilers are differences in name mangling and application binary interface (ABI). This applies to all C++ compilers in general, and not only MinGW and MSVC. If you want to learn more about interoperability pitfalls between MSVC and MinGW in particular, I encourage you to read the following articles:

    1. Interoperability of Libraries Created by Different Compiler Brands
    2. Binary-compatible C++ Interfaces