Windows 上的 GCC - Windows 上的 Ubuntu 上的 Bash (WSL)、CygWin、MinGW
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42009603/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GCC on Windows - Bash on Ubuntu on Windows (WSL), CygWin, MinGW
提问by Rithwik
I'm currently using windows 8.1 and was looking to install GCC. I found out that the ways to do this is through MinGW and CygWin (the most popular). Now I came up on the Windows Subsystem for Linux (WSL)and Bash offered on Windows in Windows 10.
我目前正在使用 Windows 8.1 并希望安装 GCC。我发现这样做的方法是通过 MinGW 和 CygWin(最流行的)。现在,我想到了 Windows 10 中的 Windows 子系统 (WSL) 和 Windows 上提供的 Bash。
Question 1.whether it is possible to have GCC installed through the Bash in Windows 10, and will it work as it does on a Linux distribution. Say you have a 'helloworld.c' file, and if I do,
问题 1.是否可以在 Windows 10 中通过 Bash 安装 GCC,它会像在 Linux 发行版上一样工作。假设你有一个“helloworld.c”文件,如果我有,
> gcc helloworld.c
$ ./a
in the bash would i get the output (assume the contents of 'helloworld.c' to be simple - a cout
statment.)
在 bash 中,我会得到输出(假设 'helloworld.c' 的内容很简单 - 一个cout
声明。)
Question 2.If it is possible then, which of the methods is preferred to use GCC on Windows. That is, a)MinGW or CygWin b)Bash on Linux on Windows. Because based on what I understood on what I read, CygWin and MinGW causes some dependencies on programs developed on them.
问题 2.如果可能的话,哪种方法更适合在 Windows 上使用 GCC。即,a)MinGW 或 CygWin b)Windows 上的 Linux 上的 Bash。因为根据我所了解的内容,CygWin 和 MinGW 会导致对在其上开发的程序产生一些依赖性。
Question 3.If you have read this far then please fill in my gap in understanding about CygWin and MinGW. That is if I use it only for compiling and running pieces of code and not application developement, it doesnt matter which of these I use, am I right? Because the code (written in C or FORTRAN), will compile and execute the same irrespective of the system, am I right?
问题 3.如果您已经读到这里,请填写我对 CygWin 和 MinGW 的理解空白。也就是说,如果我只将它用于编译和运行代码段而不是应用程序开发,那么我使用其中的哪一个都没有关系,对吗?因为代码(用 C 或 FORTRAN 编写),无论系统如何,都会编译和执行相同的,对吗?
Context. I am a student working on numerical computations (Computational Fluid Dynamics) and my main work is to develop and run CFD codes in FORTRAN. What I want to do is work on the computational code (for which we use FORTRAN mainly) on my laptop which runs on Windows. And I am not looking to develop applications or softwares for either Windows or Linux at the moment. But I'd still like to know how things work and which is the best option. Please explain in detail. Thank you.
语境。我是一名从事数值计算(计算流体动力学)的学生,我的主要工作是在 FORTRAN 中开发和运行 CFD 代码。我想做的是在我在 Windows 上运行的笔记本电脑上处理计算代码(我们主要使用 FORTRAN)。我目前不打算为 Windows 或 Linux 开发应用程序或软件。但我仍然想知道事情是如何运作的,哪个是最好的选择。请详细说明。谢谢你。
采纳答案by eewanco
To answer your first question, yes, you can do that compile under WSL.
要回答您的第一个问题,是的,您可以在 WSL 下进行编译。
To answer your other questions, let's look at MinGW. This is what the Wikipedia entry for MinGW says:
要回答您的其他问题,让我们看看 MinGW。这就是 MinGW 的维基百科条目所说的:
MinGW was forked from version 1.3.3 of Cygwin.[5] Although both Cygwin and MinGW can be used to port Unix software to Windows, they have different approaches:[16] Cygwin aims to provide a complete POSIX layer comprising a full implementation of all major Unix system calls and libraries. Compatibility is considered higher priority than performance. On the other hand, MinGW's priorities are simplicity and performance. As such, it does not provide certain POSIX APIs which cannot easily be implemented using the Windows API, such as fork(), mmap() and ioctl().[16] 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.
Windows programs written with Cygwin run on top of a copylefted compatibility DLL that must be distributed with the program, along with the program's source code. MinGW does not require a compatibility layer, since MinGW-based programs are compiled with direct calls to Windows APIs.
MinGW 是从 Cygwin 的 1.3.3 版分叉出来的。 [5] 尽管 Cygwin 和 MinGW 都可用于将 Unix 软件移植到 Windows,但它们有不同的方法:[16] Cygwin 旨在提供一个完整的 POSIX 层,包括所有主要 Unix 系统调用和库的完整实现。兼容性被认为比性能更重要。另一方面,MinGW 的优先事项是简单性和性能。因此,它不提供某些无法使用 Windows API 轻松实现的 POSIX API,例如 fork()、mmap() 和 ioctl()。[16] 使用本身已移植到 MinGW 的跨平台库编写的应用程序,例如 SDL、wxWidgets、Qt 或 GTK+,通常在 MinGW 中编译起来与在 Cygwin 中一样容易。
用 Cygwin 编写的 Windows 程序运行在一个 Copyleft 兼容 DLL 之上,该 DLL 必须与程序一起分发,以及程序的源代码。MinGW 不需要兼容层,因为基于 MinGW 的程序是通过直接调用 Windows API 编译的。
(https://en.wikipedia.org/wiki/MinGW)
( https://en.wikipedia.org/wiki/MinGW)
This is what the MinGW web page (http://www.mingw.org) says:
这是 MinGW 网页 ( http://www.mingw.org) 所说的:
MinGW, a contraction of "Minimalist GNU for Windows", is a minimalist development environment for native Microsoft Windows applications.
MinGW provides a complete Open Source programming tool set which is suitable for the development of native MS-Windows applications, and which do not depend on any 3rd-party C-Runtime DLLs. (It does depend on a number of DLLs provided by Microsoft themselves, as components of the operating system; most notable among these is MSVCRT.DLL, the Microsoft C runtime library. Additionally, threaded applications must ship with a freely distributable thread support DLL, provided as part of MinGW itself).
MinGW compilers provide access to the functionality of the Microsoft C runtime and some language-specific runtimes. MinGW, being Minimalist, does not, and never will, attempt to provide a POSIX runtime environment for POSIX application deployment on MS-Windows. If you want POSIX application deployment on this platform, please consider Cygwin instead.
MinGW 是“Minimalist GNU for Windows”的缩写,是原生 Microsoft Windows 应用程序的极简开发环境。
MinGW 提供了一套完整的开源编程工具集,适用于本机 MS-Windows 应用程序的开发,并且不依赖于任何 3rd-party C-Runtime DLL。(它确实依赖于 Microsoft 自己提供的作为操作系统组件的许多 DLL;其中最值得注意的是 MSVCRT.DLL,Microsoft C 运行时库。此外,线程应用程序必须附带一个可自由分发的线程支持 DLL,作为 MinGW 本身的一部分提供)。
MinGW 编译器提供对 Microsoft C 运行时和一些特定于语言的运行时功能的访问。MinGW 是 Minimalist,不会也永远不会尝试为 MS-Windows 上的 POSIX 应用程序部署提供 POSIX 运行时环境。如果您希望在此平台上部署 POSIX 应用程序,请考虑使用 Cygwin。
I am familiar with WSL and Cygwin more than MinGW. From what I know, MinGW is more targeted to producing reasonably portable, high-performance Windows binaries whereas Cygwin is more targeted to Unix users (or those wanting to port applications that were written for Unix/POSIX) who want a Unix-like environment under Windows with all the trimmings. As you indicated, Cygwin programs at least used to be less easily distributable to others who don't have Cygwin installed (due to license considerations, but see the link below). MinGW programs run as native Windows programs using undocumented Windows native libraries. WSL binaries don't run under Windows by themselves; they only run in the WSL environment (or possibly native Linux systems). WSL maps Linux kernel calls to Windows kernel calls, whereas Cygwin implements Unix/Posix library calls. WSL relies on a real Linux distribution to provide it's environment, whereas Cygwin relies on its own environment. (WSL has an advantage in that it will run existing binaries without recompilation.) I don't think any of this is too important to you, because you're not planning on distributing your binaries. You want high performance. According to Wikipedia, MinGW is higher performance than Cygwin, but it's also 32-bit which may be a problem with your applications. There is a 64-bit environment similar to MinGW but it's a different project.
我比MinGW更熟悉WSL和Cygwin。据我所知,MinGW 的目标是生成合理的可移植的、高性能的 Windows 二进制文件,而 Cygwin 的目标是 Unix 用户(或那些想要移植为 Unix/POSIX 编写的应用程序的人),他们想要一个类似 Unix 的环境带有所有装饰物的窗户。正如您所指出的,Cygwin 程序至少过去不太容易分发给没有安装 Cygwin 的其他人(由于许可证考虑,但请参阅下面的链接)。MinGW 程序使用未记录的 Windows 本机库作为本机 Windows 程序运行。WSL 二进制文件本身不能在 Windows 下运行;它们仅在 WSL 环境(或可能是本机 Linux 系统)中运行。WSL 将 Linux 内核调用映射到 Windows 内核调用,而 Cygwin 实现了 Unix/Posix 库调用。WSL 依赖于真正的 Linux 发行版来提供它的环境,而 Cygwin 依赖于它自己的环境。(WSL 的优势在于它无需重新编译即可运行现有的二进制文件。)我认为这些对您来说都不太重要,因为您不打算分发二进制文件。你想要高性能。根据维基百科,MinGW 的性能高于 Cygwin,但它也是 32 位的,这可能是您的应用程序的问题。有一个类似于 MinGW 的 64 位环境,但它是一个不同的项目。不要认为这些对您来说太重要了,因为您不打算分发二进制文件。你想要高性能。根据维基百科,MinGW 的性能高于 Cygwin,但它也是 32 位的,这可能是您的应用程序的问题。有一个类似于 MinGW 的 64 位环境,但它是一个不同的项目。不要认为这些对您来说太重要了,因为您不打算分发二进制文件。你想要高性能。根据维基百科,MinGW 的性能高于 Cygwin,但它也是 32 位的,这可能是您的应用程序的问题。有一个类似于 MinGW 的 64 位环境,但它是一个不同的项目。
An important consideration is whether you want to write Windows code or Unix/Linux/POSIX code. MinGW is for developing Windows applications using Windows APIs (although you can fold in some limited POSIX support); WSL and Cygwin are for developing Unix/Linux/POSIX applications. This matters for portability purposes. But if you are developing the type of programs I think you are, nearly all straight computations and very little fancy I/O, it may just boil down to personal preference or convenience. If you can come up with a small representative program that takes a significant amount of time and try running it under each environment, you can find out which has the best performance. That is going to depend I think on your own mix of operations.
一个重要的考虑因素是您要编写 Windows 代码还是 Unix/Linux/POSIX 代码。MinGW 用于使用 Windows API 开发 Windows 应用程序(尽管您可以折叠一些有限的 POSIX 支持);WSL 和 Cygwin 用于开发 Unix/Linux/POSIX 应用程序。这对于可移植性很重要。但是,如果您正在开发我认为的那种类型的程序,几乎所有直接计算和很少花哨的 I/O,它可能只是归结为个人喜好或方便。如果您能想出一个花费大量时间的小型代表性程序并尝试在每种环境下运行它,您就会发现哪个具有最佳性能。这将取决于我认为您自己的操作组合。