我想让我的c++项目跨平台,我正在考虑使用Cygwin/MinGW。 但是它们之间有什么区别呢?

另一个问题是,我是否能够在没有Cygwin/MinGW的系统上运行二进制文件?


当前回答

维基百科在这里做了一个比较。

来自Cygwin网站:

Cygwin是一个用于Windows的类似linux的环境。它由两部分组成:DLL (cygwin1.dll),作为Linux API模拟层,提供大量的Linux API功能。 提供Linux外观的工具集合。

摘自Mingw网站:

MinGW(“Minimalistic GNU for Windows”)是一个免费提供和可自由分发的Windows特定头文件和导入库的集合,结合了GNU工具集,允许人们生成不依赖任何第三方C运行时dll的本地Windows程序

其他回答

请注意,两者之间的效用行为确实不同。

例如,Cygwin tar可以fork -,因为DLL中支持fork(),而mingw版本则不支持。当试图从源代码编译mysql时,这是一个问题。

Cygwin是Microsoft Windows的类unix环境和命令行界面。

Mingw是GNU Compiler Collection (GCC)到Microsoft Windows的原生软件移植,以及一组用于Windows API的可自由分发的导入库和头文件。MinGW允许开发人员创建本地Microsoft Windows应用程序。

您可以在没有cygwin环境的情况下运行用mingw生成的二进制文件,前提是提供了所有必要的库(dll)。

维基百科说:

MinGW forked from version 1.3.3 of Cygwin. Although both Cygwin and MinGW can be used to port UNIX software to Windows, they have different approaches: Cygwin aims to provide a complete POSIX layer that provides emulations of several system calls and libraries that exist on Linux, UNIX, and the BSD variants. The POSIX layer runs on top of Windows, sacrificing performance where necessary for compatibility. Accordingly, this approach requires Windows programs written with Cygwin to run on top of a copylefted compatibility library that must be distributed with the program, along with the program's source code. MinGW aims to provide native functionality and performance via direct Windows API calls. Unlike Cygwin, MinGW does not require a compatibility layer DLL and thus programs do not need to be distributed with source code. Because MinGW is dependent upon Windows API calls, it cannot provide a full POSIX API; it is unable to compile some UNIX applications that can be compiled with Cygwin. Specifically, this applies to applications that require POSIX functionality like fork(), mmap() or ioctl() and those that expect to be run in a POSIX environment. Applications written using a cross-platform library that has itself been ported to MinGW, such as SDL, wxWidgets, Qt, or GTK+, will usually compile as easily in MinGW as they would in Cygwin. The combination of MinGW and MSYS provides a small, self-contained environment that can be loaded onto removable media without leaving entries in the registry or files on the computer. Cygwin Portable provides a similar feature. By providing more functionality, Cygwin becomes more complicated to install and maintain. It is also possible to cross-compile Windows applications with MinGW-GCC under POSIX systems. This means that developers do not need a Windows installation with MSYS to compile software that will run on Windows without Cygwin.

   MinGW (or MinGW-w64)               Cygwin
   --------------------               ------

   Your program written        Your program written
  for Unix and GNU/Linux      for Unix and GNU/Linux

             |                           |
             |                           |
             V                           V

    Heavy modifications       Almost no modifications

             |                           |
             |                           |
             V                           V

        Compilation                 Compilation
Program compiled with Cygwin ---> Compatibility layer ---> Windows API

Program compiled with MinGW (or MingGW-w64) -------------> Windows API

Cygwin试图在Windows上创建一个完整的UNIX/POSIX环境。为此,它使用了各种dll。虽然这些dll由GPLv3+覆盖,但它们的许可包含一个异常,该异常不强制派生作品由GPLv3+覆盖。MinGW是一个C/ c++编译器套件,它允许你创建Windows可执行文件而不依赖于这些dll -你只需要正常的MSVC运行时,这是任何正常的微软Windows安装的一部分。

您还可以获得一个类似UNIX/POSIX的小型环境,使用MinGW编译,称为MSYS。它不具备Cygwin的所有功能,但对于想要使用MinGW的程序员来说是理想的。