Cygwin 和 MinGW 有什么区别?
我想让我的 C++ 项目跨平台,并且我正在考虑使用 Cygwin/MinGW。 但它们之间有什么区别呢?
另一个问题是我是否能够在没有 Cygwin/MinGW 的系统上运行二进制文件?
I want to make my C++ project cross platform, and I'm considering using Cygwin/MinGW.
But what is the difference between them ?
Another question is whether I will be able to run the binary on a system without Cygwin/MinGW ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(17)
作为简化,它是这样的:
在 Cygwin 中编译某些内容,并且您正在为 Cygwin 编译它。
在 MinGW 中编译某些内容,并且您正在为 Windows 编译它。
什么是 Cygwin?
Cygwin 是一个兼容层,通过模拟基于 Unix 的操作系统提供的许多基本接口(例如管道、Unix),可以轻松地将简单的基于 Unix 的应用程序移植到 Windows。 -style 文件和目录访问等,如 POSIX 标准所记录。 Cygwin 还捆绑了 GNU 编译器集合的端口以及 Cygwin 环境的一些其他工具。
如果您有使用 POSIX 接口的现有源代码,您可以在进行很少甚至不进行任何更改后对其进行编译,以便与 Cygwin 一起使用,从而大大简化了移植简单的基于 IO 的 Unix 代码以在 Windows 上使用的过程。
Cygwin 的缺点
使用 Cygwin 编译需要将您的程序与 Cygwin 运行时环境链接起来,该环境通常会作为动态链接库
cygwin1 与您的程序一起分发。 dll
。 该库是开源的,即使您单独分发 dll,也需要使用它的软件共享兼容的开源许可证,因为其中包含头文件和接口。 因此,这对您如何许可代码施加了一些限制。什么是 MinGW?
MinGW 是用于本机 Windows 的 GNU 编译器工具的发行版,包括 GNU 编译器集合、GNU Binutils 和 GNU 调试器。 还包括允许开发本机 Windows 应用程序的头文件和库。 因此,这将作为 Microsoft Visual C++ 套件的开源替代方案。
可以使用 MinGW 来编译最初用于使用 Microsoft Visual C++ 进行编译的内容,只需进行相对较小的修改。
默认情况下,在 MinGW 的 GCC 中编译的代码将编译为本机 Windows 目标,包括 .exe 和 .dll 文件,不过您也可以使用正确的设置进行交叉编译,因为您基本上使用的是 GNU 编译器工具套件。
尽管 MingW 包含一些头文件和接口代码,允许您的代码与 Windows API 交互,但与常规标准库一样,这不会对您创建的软件施加许可限制。
MinGW 的缺点
使用 MinGW 为 Windows 编译的软件必须使用 Windows 自己的 API 来进行文件和 IO 访问。 如果您要将 Unix/Linux 应用程序移植到 Windows,这可能意味着对代码进行重大更改,因为无法再使用 POSIX 类型 API。
其他注意事项
对于任何重要的软件应用程序,例如使用图形界面、多媒体或访问系统上的设备的应用程序,您都离开了 Cygwin 可以为您做的事情的边界,并且进一步的工作将由 Cygwin 完成。使您的代码跨平台所需的。 但是,可以通过使用跨平台工具包或框架来简化此任务,这些工具包或框架允许一次编码并为任何平台成功编译代码。 如果您从一开始就使用这样的框架,那么您不仅可以减少移植到另一个平台时的麻烦,而且可以在所有平台上使用相同的图形小部件 - 窗口、菜单和控件 - 如果您正在编写一个GUI 应用程序,并让它们对用户来说是原生的。
例如,开源Qt框架是一个流行且全面的跨平台开发框架,允许构建跨操作系统(包括 Windows)运行的图形应用程序。 还有其他这样的框架。 除了大型框架之外,还有数千个更专业的软件库,它们支持多个平台,让您不必担心为不同平台编写不同的代码。
当您从一开始就开发跨平台软件时,您通常没有任何理由使用 Cygwin。 在 Windows 上编译时,您通常希望使代码能够使用 MingW 或 Microsoft Visual C/C++ 或两者进行编译。 在 Linux/*nix 上编译时,您通常会直接使用 GNU 编译器和工具进行编译。
As a simplification, it's like this:
Compile something in Cygwin and you are compiling it for Cygwin.
Compile something in MinGW and you are compiling it for Windows.
What is Cygwin?
Cygwin is a compatibility layer that makes it easy to port simple Unix-based applications to Windows, by emulating many of the basic interfaces that Unix-based operating systems provide, such as pipes, Unix-style file and directory access, and so on as documented by the POSIX standards. Cygwin is also bundled with a port of the GNU Compiler Collection and some other tools to the Cygwin environment.
If you have existing source code that uses POSIX interfaces, you may be able to compile it for use with Cygwin after making very few or even no changes, greatly simplifying the process of porting simple IO based Unix code for use on Windows.
Disadvantages of Cygwin
Compiling with Cygwin involves linking your program with the Cygwin run-time environment, which will typically be distributed with your program as the dynamically linked library
cygwin1.dll
. This library is open source and requires software using it to share a compatible open source license, even if you distribute the dll separately, because the header files and interface are included. This therefore imposes some restrictions on how you can license your code.What is MinGW?
MinGW is a distribution of the GNU compiler tools for native Windows, including the GNU Compiler Collection, GNU Binutils and GNU Debugger. Also included are header files and libraries allowing development of native Windows applications. This therefore will act as an open source alternative to the Microsoft Visual C++ suite.
It may be possible to use MinGW to compile something that was originally intended for compiling with Microsoft Visual C++ with relatively minor modifications.
By default, code compiled in MinGW's GCC will compile to a native Windows target, including .exe and .dll files, though you could also cross-compile with the right settings, since you are basically using the GNU compiler tools suite.
Even though MingW includes some header files and interface code allowing your code to interact with the Windows API, as with the regular standard libraries this doesn't impose licensing restrictions on software you have created.
Disadvantages of MinGW
Software compiled for Windows using MinGW has to use Windows' own API for file and IO access. If you are porting a Unix/Linux application to Windows this may mean significant alteration to the code because the POSIX type API can no longer be used.
Other considerations
For any non-trivial software application, such as one that uses a graphical interface, multimedia or accesses devices on the system, you leave the boundary of what Cygwin can do for you and further work will be needed to make your code cross-platform. But, this task can be simplified by using cross-platform toolkits or frameworks that allow coding once and having your code compile successfully for any platform. If you use such a framework from the start, you can not only reduce your headaches when it comes time to port to another platform but you can use the same graphical widgets - windows, menus and controls - across all platforms if you're writing a GUI app, and have them appear native to the user.
For instance, the open source Qt framework is a popular and comprehensive cross-platform development framework, allowing the building of graphical applications that work across operating systems including windows. There are other such frameworks too. In addition to the large frameworks there are thousands of more specialized software libraries in existence which support multiple platforms allowing you to worry less about writing different code for different platforms.
When you are developing cross-platform software from the start, you would not normally have any reason to use Cygwin. When compiled on Windows, you would usually aim to make your code able to be compiled with either MingW or Microsoft Visual C/C++, or both. When compiling on Linux/*nix, you'd most often compile it with the GNU compilers and tools directly.
Cygwin 是在 Windows 上创建完整的 UNIX/POSIX 环境的尝试。 为此,它使用各种 DLL。 虽然这些 DLL 受 GPLv3+ 保护,但它们的许可证包含例外,不会强制覆盖派生作品通过 GPLv3+。 MinGW 是一个 C/C++ 编译器套件,它允许您创建 Windows 可执行文件而不依赖于此类 DLL - 您只需要正常的 MSVC 运行时,它是任何正常 Microsoft Windows 安装的一部分。
您还可以获得一个类似于 UNIX/POSIX 的小型环境,使用 MinGW 编译,称为 MSYS。 它不具备 Cygwin 的所有功能,但对于想要使用 MinGW 的程序员来说是理想的选择。
Cygwin is an attempt to create a complete UNIX/POSIX environment on Windows. To do this it uses various DLLs. While these DLLs are covered by GPLv3+, their license contains an exception that does not force a derived work to be covered by the GPLv3+. MinGW is a C/C++ compiler suite which allows you to create Windows executables without dependency on such DLLs - you only need the normal MSVC runtimes, which are part of any normal Microsoft Windows installation.
You can also get a small UNIX/POSIX like environment, compiled with MinGW called MSYS. It doesn't have anywhere near all the features of Cygwin, but is ideal for programmers wanting to use MinGW.
为了添加其他答案,Cygwin 附带了 MinGW 库和标头,您可以通过使用 gcc 的 -mno-cygwin 标志来编译,而无需链接到 cygwin1.dll。 与使用普通的 MinGW 和 MSYS 相比,我更喜欢这样做。
To add to the other answers, Cygwin comes with the MinGW libraries and headers and you can compile without linking to the cygwin1.dll by using -mno-cygwin flag with gcc. I greatly prefer this to using plain MinGW and MSYS.
维基百科在此处进行了比较。
来自 Cygwin 的 网站:
来自 Mingw 的网站:
Wikipedia does a comparison here.
From Cygwin's website:
From Mingw's website:
Cygwin 使用 DLL、cygwin.dll(或者可能是一组 DLL)在 Windows 上提供类似 POSIX 的运行时。
MinGW 编译为本机 Win32 应用程序。
如果您使用 Cygwin 构建某些内容,则安装它的任何系统也将需要 Cygwin DLL。 MinGW 应用程序不需要任何特殊的运行时。
Cygwin uses a DLL, cygwin.dll, (or maybe a set of DLLs) to provide a POSIX-like runtime on Windows.
MinGW compiles to a native Win32 application.
If you build something with Cygwin, any system you install it to will also need the Cygwin DLL(s). A MinGW application does not need any special runtime.
从移植 C 程序的角度来看,理解这一点的一个好方法是举个例子:
如果我们将
stat
更改为_stat
,我们可以使用以下命令编译该程序: Microsoft Visual C。我们还可以使用 MinGW 和 Cygwin 编译该程序。在 Microsoft Visual C 下,程序将链接到 MSVC 可再发行运行时库:
mxvcrtnn.dll
,其中nn
是某个版本后缀。 为了发布这个程序,我们必须包含该 DLL。 该 DLL 提供_stat
、system
和printf
。 (我们还可以选择静态链接运行时。)在 MinGW 下,程序将链接到
msvcrt.dll
,这是一个内部的、未记录的、未版本化的库,是 Windows 的一部分,并禁止应用程序使用。 该库本质上是 MS Visual C 的可再发行运行时库的一个分支,供 Windows 本身使用。在这两种情况下,程序将具有类似的行为:
stat
函数将返回非常有限的信息,例如没有有用的权限或索引节点号。c:file.txt
根据与驱动器c:
关联的当前工作目录进行解析。system
使用cmd.exe /c
来运行外部命令。我们也可以在Cygwin下编译程序。 与 MS Visual C 使用的可再发行运行时类似,Cygwin 程序将链接到 Cygwin 的运行时库:
cygwin1.dll
(Cygwin 本身)和cyggcc_s-1.dll< /code> (GCC 运行时支持)。 由于 Cygwin 现在处于 LGPL 之下,因此我们可以将我们的程序打包(即使它不是与 GPL 兼容的自由软件),然后发布该程序。
在 Cygwin 下,库函数的行为会有所不同:
stat
函数具有丰富的功能,在大多数字段中返回有意义的值。c:file.txt
根本不被理解为包含驱动器号引用,因为c:
后面没有斜杠。 冒号被认为是名称的一部分,并以某种方式融入其中。 Cygwin 中没有针对卷或驱动器的相对路径的概念,没有“当前记录的驱动器”概念,也没有每个驱动器的当前工作目录。system
函数尝试使用/bin/sh -c
解释器。 Cygwin 将根据可执行文件的位置解析/
路径,并期望sh.exe
程序与您的可执行文件位于同一位置。Cygwin 和 MinGW 都允许您使用 Win32 函数。 如果您想调用
MessageBox
或CreateProcess
,您可以这样做。 您还可以在 MinGW 和 Cygwin 下使用gcc -mwindows
轻松构建不需要控制台窗口的程序。Cygwin 并不是严格意义上的 POSIX。 除了提供对 Windows API 的访问之外,它还提供了一些 Microsoft C 函数的自己的实现(在
msvcrt.dll
或可重新分发的msvcrtnn.dll
中找到的内容)运行时间)。 一个例子是spawn*
系列函数,例如spawnvp
。 在 Cygwin 上使用这些代替fork
和exec
是一个好主意,因为它们更好地映射到没有fork
概念的 Windows 进程创建模型>。因此:
Cygwin 程序与 MS Visual C 程序一样“原生”,因为需要库的支持。 Windows 上的编程语言实现应该提供自己的运行时,甚至是 C 语言实现。 Windows 上没有供公众使用的“libc”。
MinGW 不需要第三方 DLL,这实际上是一个缺点; 它依赖于一个未记录的、Windows 内部的 Visual C 运行时分支。 MinGW 这样做是因为 GPL 系统库例外适用于
msvcrt.dll
,这意味着可以使用 MinGW 编译和重新分发 GPL 程序。由于其与
msvcrt.dll
相比,Cygwin 对 POSIX 的支持更广泛、更深入,Cygwin 是迄今为止移植 POSIX 程序的优越环境。 由于它现在处于 LGPL 之下,因此它允许重新分发具有各种许可证(开源或闭源)的应用程序。 Cygwin 甚至包含 VT100 仿真和termios
,可与 Microsoft 控制台配合使用! 使用 tcsetattr 设置原始模式并使用 VT100 代码控制光标的 POSIX 应用程序将在 cmd.exe 窗口中正常工作。 就最终用户而言,它是一个本机控制台应用程序,通过调用 Win32 来控制控制台。但是:
/bin/sh
和其他问题。 这些差异使得 Cygwin 程序成为“非本机”程序。 如果程序将路径作为参数或从对话框中输入,Windows 用户期望该路径的工作方式与在其他 Windows 程序中的工作方式相同。 如果不能这样工作,那就有问题了。插件: LGPL 发布后不久,我启动了 Cygnal (Cygwin 本机应用程序) Library)项目提供了 Cygwin DLL 的分支,旨在解决这些问题。 程序可以在Cygwin下开发,然后使用Cygnal版本的
cygwin1.dll
进行部署,而无需重新编译。 随着这个库的改进,它将逐渐消除对 MinGW 的需求。当 Cygnal 解决路径处理问题时,将可以开发一个单独的可执行文件,当作为 Windows 应用程序与 Cygnal 一起提供时,该可执行文件可与 Windows 路径配合使用,并且当安装在
/usr/bin Cygwin 下。 在 Cygwin 下,可执行文件将透明地使用
/cygdrive/c/Users/bob
等路径。 在链接到 Cygnal 版本的 cygwin1.dll 的本机部署中,该路径没有任何意义,但它会理解 c:foo.txt。From the point of view of porting a C program, a good way to understand this is to take an example:
If we change
stat
to_stat
, we can compile this program with Microsoft Visual C. We can also compile this program with MinGW, and with Cygwin.Under Microsoft Visual C, the program will be linked to a MSVC redistributable run-time library:
mxvcrtnn.dll
, wherenn
is some version suffix. To ship this program we will have to include that DLL. That DLL provides_stat
,system
andprintf
. (We also have the option of statically linking the run-time.)Under MinGW, the program will be linked to
msvcrt.dll
, which is an internal, undocumented, unversioned library that is part of Windows, and off-limits to application use. That library is essentially a fork of the redistributable run-time library from MS Visual C for use by Windows itself.Under both of these, the program will have similar behaviors:
stat
function will return very limited information—no useful permissions or inode number, for instance.c:file.txt
is resolved according to the current working directory associated with drivec:
.system
usescmd.exe /c
for running the external command.We can also compile the program under Cygwin. Similarly to the redistributable run-time used by MS Visual C, the Cygwin program will be linked to Cygwin's run-time libraries:
cygwin1.dll
(Cygwin proper) andcyggcc_s-1.dll
(GCC run-time support). Since Cygwin is now under the LGPL, we can package with our program, even if it isn't GPL-compatible free software, and ship the program.Under Cygwin, the library functions will behave differently:
stat
function has rich functionality, returning meaningful values in most of the fields.c:file.txt
is not understood at all as containing a drive letter reference, sincec:
isn't followed by a slash. The colon is considered part of the name and somehow mangled into it. There is no concept of a relative path against a volume or drive in Cygwin, no "currently logged drive" concept, and no per-drive current working directory.system
function tries to use the/bin/sh -c
interpreter. Cygwin will resolve the/
path according to the location of your executable, and expect ash.exe
program to be co-located with your executable.Both Cygwin and MinGW allow you to use Win32 functions. If you want to call
MessageBox
orCreateProcess
, you can do that. You can also easily build a program which doesn't require a console window, usinggcc -mwindows
, under MinGW and Cygwin.Cygwin is not strictly POSIX. In addition to providing access to the Windows API, it also provides its own implementations of some Microsoft C functions (stuff found in
msvcrt.dll
or the re-distributablemsvcrtnn.dll
run-times). An example of this are thespawn*
family of functions likespawnvp
. These are a good idea to use instead offork
andexec
on Cygwin since they map better to the Windows process creation model which has no concept offork
.Thus:
Cygwin programs are no less "native" than MS Visual C programs on grounds of requiring the accompaniment of libraries. Programming language implementations on Windows are expected to provide their own run-time, even C language implementations. There is no "libc" on Windows for public use.
The fact that MinGW requires no third-party DLL is actually a disadvantage; it is depending on an undocumented, Windows-internal fork of the Visual C run-time. MinGW does this because the GPL system library exception applies to
msvcrt.dll
, which means that GPL-ed programs can be compiled and redistributed with MinGW.Due to its much broader and deeper support for POSIX compared to
msvcrt.dll
, Cygwin is by far the superior environment for porting POSIX programs. Since it is now under the LGPL, it allows applications with all sorts of licenses, open or closed source, to be redistributed. Cygwin even contains VT100 emulation andtermios
, which work with the Microsoft console! A POSIX application that sets up raw mode withtcsetattr
and uses VT100 codes to control the cursor will work right in thecmd.exe
window. As far as the end-user is concerned, it's a native console app making Win32 calls to control the console.However:
/bin/sh
and other issues. These differences are what render Cygwin programs "non-native". If a program takes a path as an argument, or input from a dialog box, Windows users expect that path to work the same way as it does in other Windows programs. If it doesn't work that way, that's a problem.Plug: Shortly after the LGPL announcement, I started the Cygnal (Cygwin Native Application Library) project to provide a fork of the Cygwin DLL which aims to fix these issues. Programs can be developed under Cygwin, and then deployed with the Cygnal version of
cygwin1.dll
without recompiling. As this library improves, it will gradually eliminate the need for MinGW.When Cygnal solves the path handling problem, it will be possible to develop a single executable which works with Windows paths when shipped as a Windows application with Cygnal, and seamlessly works with Cygwin paths when installed in your
/usr/bin
under Cygwin. Under Cygwin, the executable will transparently work with a path like/cygdrive/c/Users/bob
. In the native deployment where it is linking against the Cygnal version ofcygwin1.dll
, that path will make no sense, whereas it will understandc:foo.txt
.阅读这些已回答的问题以了解 Cygwin 和 MinGW 之间的区别。
问题#1:我想创建一个应用程序,只需编写一次源代码、编译一次并在任何平台(例如 Windows、Linux 和 Mac OS X...)中运行它。
问题#2:我想创建一个只编写一次源代码的应用程序,但单独为任何平台(例如Windows、Linux 和Mac OS X ...)编译源代码都没有问题。
问题#3:回答问题#2时,每个平台使用不同的编译器是很困难的,有没有跨平台的编译器?
问题#4:C 或C++ 标准头文件不提供任何高级编程功能(如多线程)。 我能做些什么?
因此:
要在Windows中利用GCC跨平台编译器的优势,请使用MinGW。
要在 Windows 中利用 POSIX 标准高级编程功能和工具的优势,请使用 Cygwin。
Read these answered questions to understand the difference between Cygwin and MinGW.
Question #1: I want to create an application that I write source code once, compile it once and run it in any platforms (e.g. Windows, Linux and Mac OS X…).
Question #2: I want to create an application that I write source code once but there is no problem that I compile the source code for any platforms separately (e.g. Windows, Linux and Mac OS X …).
Question #3: In answer of question #2, it is difficult using different compiler for each platform, is there any cross platform compiler?
Question #4: C or C++ standard header files do not provide any advanced programming features like multi-threading. What can I do?
Thus:
To use advantage of GCC cross platform compiler in Windows, use MinGW.
To use advantage of POSIX standard advanced programming features and tools in Windows, use Cygwin.
其他答案已经达到目标了。 我只是想添加一个插图以便快速掌握。
Other answers already hit the target. I just want to add an illustration for a quick catch.
维基百科说:
Wikipedia Says:
不要忽视 AT&T 的 U/Win 软件,该软件的设计帮助您在 Windows 上编译 Unix 应用程序(最新版本 - 2012-08-06;使用 Eclipse 公共许可证,版本 1.0)。
像 Cygwin 一样,它们必须与库竞争; 在他们的例子中
POSIX.DLL
。 AT&T 的员工都是出色的工程师(为您带来 ksh 和 dot 的团队),他们的东西值得一看。Don't overlook AT&T's U/Win software, which is designed to help you compile Unix applications on windows (last version - 2012-08-06; uses Eclipse Public License, Version 1.0).
Like Cygwin they have to run against a library; in their case
POSIX.DLL
. The AT&T guys are terrific engineers (same group that brought you ksh and dot) and their stuff is worth checking out.要在非免费/专有/闭源应用程序中使用 Cygwin,您需要花费数万美元购买“许可证购买"; 这会导致标准许可条款失效,并付出相当大的代价。 谷歌“cygwin许可证成本”并看到前几个结果。
对于 mingw 来说,不会产生这样的成本,并且许可证(PD、BSD、MIT)非常宽松。 最多您可能需要为您的应用程序提供许可证详细信息,例如使用 mingw64-tdm 时所需的 winpthreads 许可证。
感谢 Izzy Helianthus 的编辑:商业许可证不再可用或不再需要,因为 API 库在 Cygwin 的 Winsup 子目录中找到 现在根据 LGPL(而不是完整的 GPL)分发。
To use Cygwin in a non-free / proprietary / closed-source application, you'll need to fork out tens of thousands of dollars for a "license buyout" from Red Hat; this invalidates the standard licensing terms at a considerable cost. Google "cygwin license cost" and see first few results.
For mingw, no such cost is incurred, and the licenses (PD, BSD, MIT) are extremely permissive. At most you may be expected to supply license details with your application, such as the winpthreads license required when using mingw64-tdm.
EDIT thanks to Izzy Helianthus: The commercial license is no longer available or necessary because the API library found in the winsup subdirectory of Cygwin is now being distributed under the LGPL, as opposed to the full GPL.
Cygwin 模拟整个 POSIX 环境,而 MinGW 是仅用于编译的最小工具集(编译本机 Win 应用程序)。因此,如果您想让您的项目跨平台,那么两者之间的选择是显而易见的,MinGW。
尽管您可能会考虑在 Windows 上使用 VS,在 Linux/Unices 上使用 GCC。 大多数开源项目都这样做(例如 Firefox 或 Python)。
Cygwin emulates entire POSIX environment, while MinGW is minimal tool set for compilation only (compiles native Win application.) So if you want to make your project cross-platform the choice between the two is obvious, MinGW.
Although you might consider using VS on Windows, GCC on Linux/Unices. Most open source projects do that (e.g. Firefox or Python).
请注意,两者之间的实用程序行为可能确实有所不同。
例如,Cygwin tar 可以 fork - 因为 DLL 中支持 fork() - 而 mingw 版本则不能。 当尝试从源代码编译 mysql 时,这是一个问题。
Note that utility behaviour can genuinely vary between the two.
For example, Cygwin tar can fork - because fork() is supported in the DLL - where the mingw version cannot. This is a problem when trying to compile mysql from source.
Cygwin 旨在为 Windows 提供或多或少完整的 POSIX 环境,其中包括一组旨在提供成熟的类似 Linux 平台的广泛工具。 相比之下,MinGW 和 MSYS 提供了一个轻量级、简约的类似 POSIX 的层,仅提供诸如 gcc 和 bash 等更重要的工具。 由于 MinGW 的方法更为简约,因此它无法提供 Cygwin 提供的 POSIX API 覆盖程度,因此无法构建某些可以在 Cygwin 上编译的程序。
就两者生成的代码而言,Cygwin 工具链依赖于动态链接到大型运行时库 cygwin1.dll,而 MinGW 工具链将代码编译为动态链接到 Windows 本机 C 的二进制文件库
msvcrt.dll
以及静态到glibc
的部分。 因此,Cygwin 可执行文件更加紧凑,但需要单独的可再发行 DLL,而 MinGW 二进制文件可以独立发布,但往往更大。基于 Cygwin 的程序需要单独的 DLL 才能运行这一事实也会导致许可限制。 Cygwin 运行时库根据 GPLv3 获得许可,但对于具有 OSI 兼容许可证的应用程序有一个链接例外,因此希望围绕 Cygwin 构建闭源应用程序的开发人员必须从 Red Hat 获得商业许可证。 另一方面,MinGW 代码可以在开源和闭源应用程序中使用,因为标头和库是经过许可的。
Cygwin is designed to provide a more-or-less complete POSIX environment for Windows, including an extensive set of tools designed to provide a full-fledged Linux-like platform. In comparison, MinGW and MSYS provide a lightweight, minimalist POSIX-like layer, with only the more essential tools like
gcc
andbash
available. Because of MinGW's more minimalist approach, it does not provide the degree of POSIX API coverage Cygwin offers, and therefore cannot build certain programs which can otherwise be compiled on Cygwin.In terms of the code generated by the two, the Cygwin toolchain relies on dynamic linking to a large runtime library,
cygwin1.dll
, while the MinGW toolchain compiles code to binaries that link dynamically to the Windows native C librarymsvcrt.dll
as well as statically to parts ofglibc
. Cygwin executables are therefore more compact but require a separate redistributable DLL, while MinGW binaries can be shipped standalone but tend to be larger.The fact that Cygwin-based programs require a separate DLL to run also leads to licensing restrictions. The Cygwin runtime library is licensed under GPLv3 with a linking exception for applications with OSI-compliant licenses, so developers wishing to build a closed-source application around Cygwin must acquire a commercial license from Red Hat. On the other hand, MinGW code can be used in both open-source and closed-source applications, as the headers and libraries are permissively licensed.
Cygwin
使用兼容层,而MinGW
是本机的。 这是主要区别之一。Cygwin
uses a compatibility layer, whileMinGW
is native. That is one of the main differences.Cygwin 是 Microsoft Windows 的类 Unix 环境和命令行界面。
Mingw 是 GNU 编译器集合 (GCC) 到 Microsoft Windows 的本机软件端口,以及一组可免费分发的 Windows API 导入库和头文件。 MinGW 允许开发人员创建本机 Microsoft Windows 应用程序。
您可以在没有 cygwin 环境的情况下运行使用 mingw 生成的二进制文件,前提是所有必需的库 (DLL) 都存在。
Cygwin is is a Unix-like environment and command-line interface for Microsoft Windows.
Mingw is a native software port of the GNU Compiler Collection (GCC) to Microsoft Windows, along with a set of freely distributable import libraries and header files for the Windows API. MinGW allows developers to create native Microsoft Windows applications.
You can run binaries generated with
mingw
without thecygwin
environment, provided that all necessary libraries (DLLs) are present.