简体   繁体   English

C++ windows 二进制文件:与 MinGW 一起使用的条件

[英]C++ windows binaries: conditions to be used with MinGW

I am new to C++ and I am now struggling with compiling and linking.我是 C++ 新手,现在正在努力编译和链接。 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) ).最近我一直在使用 cmake 和 make 重新编译一个使用 Boost 的库(mlpack)( Cmake 没有找到 boost 1.51 (windows 8) )。

In a first attempt, I downloaded precompiled binaries for windows.在第一次尝试中,我下载了 Windows 的预编译二进制文件。 This did not work out well and I have been explained the binaries I was using were for MSVC, not MinGW, therefore troubles.这并没有奏效,我已经解释过我使用的二进制文件是用于 MSVC,而不是 MinGW,因此很麻烦。 And indeed, after recompiling boost using MinGW, things went ok.事实上,在使用 MinGW 重新编译 boost 之后,一切顺利。

Here I would just like to get an intuition what would be the differences between binaries for MSVC and MinGW.在这里,我只想了解 MSVC 和 MinGW 的二进制文件之间的区别。 I (naively?) thought binaries were specific to OS/processor.我(天真地?)认为二进制文件是特定于操作系统/处理器的。 What do the binaries for MSVC contains that make them unusable by MinGW ? MSVC 的二进制文件包含哪些使 MinGW 无法使用它们的内容?

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.组合由 MSVC 和 MinGW 生成的工件(静态/共享库)相对容易(这通常适用于其他 C 编译器),只要它们导出纯 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.这使得 C API 非常可移植,这也是许多流行库仍然喜欢使用纯 C API 的主要原因之一。

The story with C++ is completely different. C++ 的故事完全不同。 The most notorious obstacles for proper interoperability between artifacts produced by different C++ compilers are differences in name mangling and application binary interface (ABI).由不同 C++ 编译器生成的工件之间正确互操作性的最臭名昭著的障碍是名称修改应用程序二进制接口(ABI) 的差异。 This applies to all C++ compilers in general, and not only MinGW and MSVC.这通常适用于所有 C++ 编译器,而不仅仅是 MinGW 和 MSVC。 If you want to learn more about interoperability pitfalls between MSVC and MinGW in particular, I encourage you to read the following articles:如果您想详细了解 MSVC 和 MinGW 之间的互操作性陷阱,我建议您阅读以下文章:

  1. Interoperability of Libraries Created by Different Compiler Brands 不同编译器品牌创建的库的互操作性
  2. Binary-compatible C++ Interfaces二进制兼容的 C++ 接口

To be simple.要简单。

Windows speaks French . Windows 讲French
MinGW speaks French , German and English . MinGW 会说FrenchGermanEnglish
Unix systems speak German . Unix 系统说German


The MSVC binaries are written in French . MSVC 二进制文件是用French编写的。
The MinGW binaries are written in FrenchAngloGerman . MinGW 二进制文件是用FrenchAngloGerman编写的。
The UNIX binaries are written in German . UNIX 二进制文件是用German编写的。


Windows needs MinGW to translate some of the German and English to French before it can understand everything. Windows 需要 MinGW 将一些GermanEnglishFrench然后才能理解所有内容。


MinGW is not like the other programs. MinGW 与其他程序不同。 It is basically a mini OS between Windows and Linux.它基本上是一个介于 Windows 和 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.您在 Windows 上的 MinGW 上开发程序的事实并不意味着它们可以在纯 Windows 上运行而没有任何问题。 You still need to ship or distribute the MinGW libraries and executables that you used with your program.您仍然需要发布或分发与您的程序一起使用的 MinGW 库和可执行文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM