Cygwin 和 MinGW 有什么区别? [英] What is the difference between Cygwin and MinGW?

查看:27
本文介绍了Cygwin 和 MinGW 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

解决方案

简单来说,是这样的:

  • 在 Cygwin 中编译一些东西,你正在为 Cygwin 编译它.

  • 在 MinGW 中编译一些东西,你正在为 Windows 编译它.

关于 Cygwin

Cygwin 是一个兼容层,通过模拟基于 Unix 的操作系统提供的许多基本接口,例如管道、Unix 样式的文件和目录访问,以及如 POSIX 标准所记载.如果您有使用这些接口的现有源代码,您可以在很少甚至不做任何更改后将其编译为与 Cygwin 一起使用,这大大简化了移植简单的基于 IO 的 Unix 代码以在 Windows 上使用的过程.

当您分发软件时,接收者需要将它与 Cygwin 运行时环境(由文件 cygwin1.dll 提供)一起运行.您可以将其与您的软件一起分发,但您的软件必须遵守其开源许可.即使只是将您的软件与其链接,但单独分发 dll,仍然会对您的代码施加许可限制.

关于MinGW

MinGW 旨在简单地成为 GNU 的 Windows 开发工具的一个端口.它不试图模拟或提供与 Unix 的全面兼容性,而是提供可在 Windows 中本地使用的 GNU 编译器集合、GNU Binutils 和 GNU 调试器的版本.它还包括允许在您的代码中使用 Windows 的本机 API 的头文件.

因此,您的应用程序需要使用 Windows API 专门针对 Windows 进行编程,如果创建的应用程序依赖于在标准 Unix 环境中运行并使用特定于 Unix 的功能,则这可能意味着重大更改.默认情况下,在 MinGW 的 GCC 中编译的代码将编译为本地 Windows X86 目标,包括 .exe 和 .dll 文件,但您也可以使用正确的设置进行交叉编译,因为您基本上使用的是 GNU 编译器工具套件.

MinGW 是使用 Microsoft Visual C++ 的免费开源替代方案Windows 上的编译器及其关联的链接/制作工具.在某些情况下,可以使用 MinGW 编译一些旨在用 Microsoft Visual C++ 编译的内容,而无需进行太多修改.

尽管 MingW 包含一些头文件和接口代码,允许您的代码与 Windows API 交互,但与常规标准库一样,这不会对您创建的软件施加许可限制.

其他注意事项

对于任何非平凡的软件应用程序,例如使用图形界面、多媒体或访问系统上的设备的应用程序,您离开了 Cygwin 可以为您做什么的边界,并且需要进一步的工作来使您的代码跨越-平台.但是,可以通过使用跨平台工具包或框架来简化此任务,这些工具包或框架允许一次编码并让您的代码针对任何平台成功编译.如果您从一开始就使用这样的框架,那么您不仅可以减少移植到另一个平台时的麻烦,而且您可以在所有平台上使用相同的图形小部件 - 窗口、菜单和控件 - 如果您正在编写一个GUI 应用程序,并让它们对用户来说是原生的.

例如,开源 Qt 框架 是一种流行且全面的跨平台开发框架,允许构建跨操作系统(包括 Windows)工作的图形应用程序.还有其他这样的框架.除了大型框架之外,还有数千个更专业的软件库支持多个平台,让您无需担心为不同平台编写不同的代码.

当您从一开始就开发跨平台软件时,您通常没有任何理由使用 Cygwin.在 Windows 上编译时,您的目标通常是使您的代码能够使用 MingW 或 Microsoft Visual C/C++ 或两者进行编译.在 Linux/*nix 上编译时,您通常会直接使用 GNU 编译器和工具进行编译.

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 ?

解决方案

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.

About 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. If you have existing source code that uses these 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.

When you distribute your software, the recipient will need to run it along with the Cygwin run-time environment (provided by the file cygwin1.dll). You may distribute this with your software, but your software will have to comply with its open source license. Even just linking your software with it, but distributing the dll separately, can still impose license restrictions on your code.

About MinGW

MinGW aims to simply be a port of GNU's development tools for Windows. It does not attempt to emulate or provide comprehensive compatibility with Unix, other that to provide a version of the GNU Compiler Collection, GNU Binutils and GNU Debugger that can be used natively in Windows. It also includes header files allowing the use of Windows' native API in your code.

As a result your application needs to specifically be programmed for Windows, using the Windows API, which may mean significant alteration if it was created to rely on being run in a standard Unix environment and use Unix-specific features. By default, code compiled in MinGW's GCC will compile to a native Windows X86 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.

MinGW is a free and open source alternative to using the Microsoft Visual C++ compiler and its associated linking/make tools on Windows. It may be possible in some cases to use MinGW to compile something that was intended for compiling with Microsoft Visual C++ without too many modifications.

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.

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 和 MinGW 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆