2

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 ?

Community
  • 1
  • 1
Vince
  • 3,979
  • 10
  • 41
  • 69

2 Answers2

2

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
Alexander Shukaev
  • 16,674
  • 8
  • 70
  • 85
1

To be simple.

Windows speaks French.
MinGW speaks French, German and English.
Unix systems speak German.


The MSVC binaries are written in French.
The MinGW binaries are written in FrenchAngloGerman.
The UNIX binaries are written in German.


Windows needs MinGW to translate some of the German and English to French before it can understand everything.


MinGW is not like the other programs. It is basically a mini OS between Windows and Linux. So mostly it needs a modified form of binaries to work properly. The fact that you develop your program on Windows on MinGW doesn't mean they will run on pure Windows with out any problems. You still need to ship or distribute the MinGW libraries and executables that you used with your program.

stardust
  • 5,918
  • 1
  • 18
  • 20
  • I am still confused. Does this mean that once you compiled for your system, your libraries will still not be usable by all programs in your system ? Does it mean you need to compile for every existing compiler ? And you can never download any binaries except those which has been compile for your specific compiler ? For the language analogy, the libraries for MSVC are in french, MinGW speaks also french, and windows speaks french, no ? – Vince Apr 15 '13 at 02:07
  • @Vince I have tried to explain it a bit more. However I think Haroogan has provided some good links on why the issues arise. You should check them out. – stardust Apr 15 '13 at 02:21
  • Thanks ! Just to clarify: now I downloaded iconv binaries, and I have a folder lib that contains iconv.lib ... it is not reasonable to assume linking to this library will work when compiling other libraries using mingw ? how to know if these libraries are ok or not ? – Vince Apr 15 '13 at 04:16