我想让我的c++项目跨平台,我正在考虑使用Cygwin/MinGW。 但是它们之间有什么区别呢?
另一个问题是,我是否能够在没有Cygwin/MinGW的系统上运行二进制文件?
我想让我的c++项目跨平台,我正在考虑使用Cygwin/MinGW。 但是它们之间有什么区别呢?
另一个问题是,我是否能够在没有Cygwin/MinGW的系统上运行二进制文件?
当前回答
为了补充其他答案,Cygwin附带了MinGW库和头文件,你可以在不链接到cygwin1.dll的情况下使用-mno-cygwin标志与gcc进行编译。比起使用普通的MinGW和MSYS,我更喜欢这个。
其他回答
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 and bash 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.
就两者生成的代码而言,Cygwin工具链依赖于到大型运行时库cygwin1.dll的动态链接,而MinGW工具链将代码编译为二进制文件,动态链接到Windows原生C库msvcrt.dll,以及静态链接到glibc的某些部分。Cygwin可执行文件因此更紧凑,但需要一个单独的可重新分发的DLL,而MinGW二进制文件可以独立发布,但往往更大。
基于cygwin的程序需要单独的DLL才能运行,这一事实也导致了许可限制。Cygwin运行时库是在GPLv3下授权的,对于具有符合osi的许可证的应用程序有一个链接例外,因此希望围绕Cygwin构建闭源应用程序的开发人员必须从Red Hat获得商业许可证。另一方面,MinGW代码既可以用于开源应用程序,也可以用于闭源应用程序,因为其头文件和库都是经过许可的。
Cygwin使用兼容层,而MinGW是本地的。这是主要的区别之一。
请注意,两者之间的效用行为确实不同。
例如,Cygwin tar可以fork -,因为DLL中支持fork(),而mingw版本则不支持。当试图从源代码编译mysql时,这是一个问题。
其他答案已经击中了目标。我只是想增加一个快速捕捉的例子。
维基百科说:
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.