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

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


当前回答

不要忽视AT&T的U/Win软件,该软件旨在帮助您在windows上编译Unix应用程序(最新版本- 2012-08-06;使用Eclipse公共许可证,版本1.0)。

像Cygwin一样,他们必须与图书馆赛跑;在它们的情况下是POSIX.DLL。AT&T的人都是很棒的工程师(同样的团队给你带来了ksh和dot),他们的东西值得一看。

其他回答

阅读这些已回答的问题,了解Cygwin和MinGW之间的区别。


问题#1:我想创建一个应用程序,我写源代码一次,编译一次,并在任何平台上运行(例如Windows, Linux和Mac OS X…)

答案#1:把源代码写进去 JAVA。编译源代码一次,然后 在任何地方运行它。


问题2:我想创建一个应用程序,我只写一次源代码,但我可以分别为任何平台编译源代码(例如Windows, Linux和Mac OS X…)

答案#2:用C语言编写源代码 或c++。使用标准头文件 只有。使用合适的编译器 平台(如Visual Studio for Windows, GCC for Linux, XCode for Mac)。注意,您不应该使用任何一种 高级编程特性 全部编译源代码 成功的平台。如果你使用 没有C或c++标准类或 函数,你的源代码没有 在其他平台编译。


问题#3:回答问题#2,在每个平台上使用不同的编译器是困难的,有跨平台的编译器吗?

答案#3:是的,使用GCC编译器。它 是一个跨平台编译器。来 在Windows中编译源代码 使用MinGW提供GCC编译器 并编译您的源代码 代码转换为本地Windows程序。不 使用任何高级编程特性 (如Windows API)来编译你的 所有平台的源代码 成功。如果你使用Windows API 函数,你的源代码没有 在其他平台编译。


问题4:C或c++标准头文件不提供任何高级编程特性,如多线程。我该怎么办?

Answer #4: You should use POSIX (Portable Operating System Interface [for UNIX]) standard. It provides many advanced programming features and tools. Many operating systems fully or partly POSIX compatible (like Mac OS X, Solaris, BSD/OS and ...). Some operating systems while not officially certified as POSIX compatible, conform in large part (like Linux, FreeBSD, OpenSolaris and ...). Cygwin provides a largely POSIX-compliant development and run-time environment for Microsoft Windows.


因此:

要在Windows下充分利用GCC跨平台编译器的优势,请使用MinGW。

要在Windows中使用POSIX标准高级编程特性和工具的优势,请使用Cygwin。

维基百科说:

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.

要在非免费/专有/闭源应用程序中使用Cygwin,您需要向Red Hat支付数万美元的“许可证买断”;这会使标准许可条款失效,并付出相当大的代价。谷歌“cygwin许可证成本”,并看到前几个结果。

对于mingw,不产生这种成本,并且许可证(PD、BSD、MIT)是非常允许的。您最多可能需要在应用程序中提供许可细节,例如使用mingw64-tdm时所需的winpthreads许可。

由Izzy Helianthus提供的编辑:商业许可证不再可用,也不再需要,因为Cygwin的winsup子目录中的API库现在是在LGPL下发布的,而不是完全的GPL。

Cygwin使用兼容层,而MinGW是本地的。这是主要的区别之一。

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

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

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