64

I'm an avid Python user and it seems that I require MinGW to be installed on my Windows machine to compile some libraries. I'm a little confused about MinGW and GCC. Here's my question (from a real dummy point of view):
我是一个狂热的 Python 用户,似乎我需要在我的 Windows 机器上安装 MinGW 来编译一些库。我对 MinGW 和 GCC 有点困惑。这是我的问题(从真实的虚拟角度来看):

So Python is language which both interpreted and compiled. There are Linux and Windows implementations of Python which one simply installs and used the binary to a execute his code. They come bundled with a bunch of built-in libraries that you can use. It's the same with Ruby from what I've read.
所以Python是一种既能解释又能编译的语言。有 Python 的 Linux 和 Windows 实现,只需安装并使用二进制文件来执行他的代码。它们与您可以使用的一堆内置库捆绑在一起。从我所读到的内容来看,Ruby 也是如此。

Now, I've done a tiny bit a of C and I know that one has a to compile it. It has its built-in libraries which seem to be called header files which you can use. Now, back in the school day's, C, was writing code in a vi-like IDE called Turbo-C and then hitting F9 to compile it. That's pretty much where my C education ends.
现在,我已经做了一点 C 语言,我知道有一个可以编译它。它有其内置库,这些库似乎被称为您可以使用的头文件。现在,回到学生时代,C 是在一个名为 Turbo-C 的类似 vi 的 IDE 中编写代码,然后按 F9 进行编译。我的C教育差不多就到此为止了。

What is MinGW and what is GCC? I've been mainly working on Windows systems and have even recently begun using Cygwin. Aren't they the same?
什么是 MinGW,什么是 GCC?我主要在 Windows 系统上工作,甚至最近开始使用 Cygwin。它们不是一样的吗?

A simple explanation hitting these areas would be helpful.
对这些区域进行简单的解释会有所帮助。

(My apologies if this post sounds silly/stupid. I thought I'd ask here. Ignoring these core bits never made anyone a better programmer.)
(如果这篇文章听起来很傻/愚蠢,我深表歉意。我想我会在这里问。忽略这些核心位永远不会让任何人成为更好的程序员。

Thanks everyone. 谢谢大家。

CC BY-SA 3.0
2
  • Have you read the welcome page on www.mingw.org? Does it answer any questions for you, or raise new, more specific ones? You may also want to read some introductory information on how compilers/compiled languages work.
    您是否阅读过 www.mingw.org 上的欢迎页面?它是否回答了您的任何问题,或者提出了新的、更具体的问题?您可能还想阅读一些关于编译器/编译语言如何工作的介绍性信息。
    – eriktous
    Commented Oct 17, 2011 at 11:55
  • 1
    I have read. It doesn't answer much. First sentence means nada: "Mingw-w64 is an advancement of the original mingw.org project, created to support the GCC compiler on Windows systems."
    我已经读过了。它没有回答太多。第一句话的意思是nada:“Mingw-w64是原始 mingw.org 项目的改进,旨在支持Windows系统上的GCC编译器。
    – WhyWhat
    Commented Jun 27, 2022 at 19:36

5 Answers 5

59

MinGW is a complete GCC toolchain (including half a dozen frontends, such as C, C++, Ada, Go, and whatnot) for the Windows platform which compiles for and links to the Windows OS component C Runtime Library in msvcrt.dll. Rather it tries to be minimal (hence the name).
MinGW 是一个完整的 GCC 工具链(包括六个前端,如 C、C++、Ada、Go 等),用于 Windows 平台,它为 Windows 操作系统组件 C 运行时库编译并链接到 msvcrt.dll。相反,它试图做到最小(因此得名)。

This means, unlike Cygwin, MinGW does not attempt to offer a complete POSIX layer on top of Windows, but on the other hand it does not require you to link with a special compatibility library.
这意味着,与Cygwin不同,MinGW不尝试在Windows之上提供完整的POSIX层,但另一方面,它不需要您与特殊的兼容性库链接。

It therefore also does not have any GPL-license implications for the programs you write (notable exception: profiling libraries, but you will not normally distribute those so that does not matter).
因此,它对你编写的程序也没有任何 GPL 许可证的影响(值得注意的例外:分析库,但你通常不会分发这些库,所以这无关紧要)。

The newer MinGW-w64 comes with a roughly 99% complete Windows API binding (excluding ATL and such) including x64 support and experimental ARM implementations. You may occasionally find some exotic constant undefined, but for what 99% of the people use 99% of the time, it just works perfectly well.
较新的 MinGW-w64 附带大约 99% 的完成 Windows API 绑定(不包括 ATL 等),包括 x64 支持和实验性 ARM 实现。你可能偶尔会发现一些奇特的常数未定义,但对于 99% 的人 99% 的时间使用的东西来说,它运行良好。

You can also use the bigger part of what's in POSIX, as long as it is implemented in some form under Windows. The one major POSIX thing that does not work with MinGW is fork, simply because there is no such thing under Windows (Cygwin goes through a lot of pain to implement it).
您还可以使用POSIX中的大部分内容,只要它在Windows下以某种形式实现即可。与 MinGW 不起作用的一件主要 POSIX 事情是 fork ,仅仅是因为 Windows 下没有这样的东西(Cygwin 为实现它经历了很多痛苦)。

There are a few other minor things, but all in all, most things kind of work anyway.
还有一些其他的小事,但总而言之,大多数事情都是有效的。

So, in a very very simplified sentence: MinGW(-w64) is a "no-frills compiler thingie" that lets you write native binary executables for Windows, not only in C and C++, but also other languages.
所以,用一个非常非常简化的句子来说:MinGW(-w64)是一个“简洁的编译器”,它让你为Windows编写原生二进制可执行文件,不仅可以用C和C++,还可以用其他语言。

CC BY-SA 4.0
9
  • 1
    Do you know the history behind the -w64 fork of MinGW and why they so inconveniently chose to call it "w64"?
    你知道MinGW -w64 分叉背后的历史吗,以及为什么他们如此不方便地选择称之为“w64”?
    Commented Aug 17, 2016 at 10:08
  • 2
    What is exactly is a programming's language 'frontend'?
    编程语言的“前端”到底是什么?
    – xtrinch
    Commented Jul 7, 2017 at 6:28
  • 1
    @Nim: The programming language is the frontend, more or less. A compiler often/usually consists of a frontend (for example C or C++) which gets parsed into an abstract syntax tree and translated to some unspecified intermediate representation of sorts. That intermediate representation is then transformed by the backend into a machine-specific number of instructions. Some compilers (LLVM) make this more explict, others make it less explict, but in principle they nevertheless work the same.
    @Nim:编程语言或多或少是前端。编译器通常由前端(例如C或C++)组成,该前端被解析为抽象语法树,并转换为某种未指定的中间表示。然后,该中间表示由后端转换为特定于机器的指令数量。一些编译器(LLVM)使它更明确,其他编译器则使其不那么明确,但原则上它们的工作方式相同。
    – Damon
    Commented Jul 7, 2017 at 7:35
  • 2
    "...compiles for and links to the Windows OS component C Runtime Library in msvcrt.dll..." - I thought that MingW did not rely on msvcrt.dll, and instead came with its own standard library .dll. Am I wrong?
    "...编译并链接到 Windows 操作系统组件 C 运行时库中的 msvcrt.dll...“ - 我以为 MingW 并不依赖 msvcrt.dll ,而是自带了自己的标准库 .dll 。我错了吗?
    – Aviv Cohn
    Commented Mar 28, 2020 at 21:19
  • 1
    And what is "GCC"?
    什么是“海湾合作委员会”?
    Commented Apr 27, 2021 at 20:22
30

To compile C program you need a C implementation for your specific computer.
要编译 C 程序,您需要针对特定计算机的 C 实现。

C implementations consist, basically, of a compiler (its preprocesser and headers) and a library (the ready-made executable code).
C 实现基本上由编译器(其预处理器和头文件)和库(现成的可执行代码)组成。

On a computer with Windows installed, the library that contains most ready-made executable code is not compatible with gcc compiler ... so to use this compiler in Windows you need a different library: that's where MinGW enters. MinGW provides, among other things, the library(ies) needed for making a C implementation together with gcc.
在安装了 Windows 的计算机上,包含大多数现成可执行代码的库与 gcc 编译器不兼容......因此,要在 Windows 中使用此编译器,您需要一个不同的库:这就是 MinGW 入口。 MinGW 除其他事项外,提供了制作 C 实现所需的库 gcc


The Windows library and MSVC together make a different implementation.
Windows 库和 MSVC 一起实现不同的实现。

CC BY-SA 3.0
4
  • 3
    Good simple expaination.
    很好的简单阐述。
    – RKum
    Commented Jul 14, 2020 at 8:05
  • @pmg so library code is not compatible for gcc compiler but we write code all that in int main() is compatible for gcc compiler right ?
    @pmg所以库代码与 GCC 编译器不兼容,但我们编写的代码与 int main() GCC 编译器兼容,对吧?
    Commented Aug 20, 2021 at 14:43
  • In header file declaration is there and in library files definition is there. So after compilation linker associates respective readymade code in object file. This is only you referring ` library that contains most ready-made executable code` right ? but this happening after compilation so why it's problem with gcc compiler ? I think I am missing some basic but I am not understanding ? Commented Aug 20, 2021 at 14:54
  • Not quite right... (parts of) the standard library are installed with the Operating System (my 3-year old niece computer has that functionality built in). When you install a compiler (with headers and [extra] standard library ready-made functions) the connection between the compiler and the OS part of the standard library is mostly well established. MinGW just says: "don't link with the OS functions, use these ones instead".
    – pmg
    Commented Aug 22, 2021 at 7:03
4

MinGW is a suite of development tools that contains GCC (among others), and GCC is a C compiler within that suite.

CC BY-SA 3.0
2
4

MinGW is an implementation of most of the GNU building utilities, like gcc and make on windows, while gcc is only the compiler. Cygwin is a lot bigger and sophisticated package, wich installs a lot more than MinGW.

CC BY-SA 3.0
4

The only reason for existence of MinGW is to provide linux-like environment for developers not capable of using native windows tools. It is inferior in almost every respect to Microsoft tooolchains on Win32/Win64 platforms, BUT it provides environment where linux developer does not have to learn anything new AND he/she can compile linux code almost without modifications. It is a questionable approach , but many people find that convenience more important than other aspects of the development . It has nothing to do with C or C++ as was indicated in earlier answers, it has everything to do with the environment developer wants. Argument about GNU toolchains on windows and its nessessety, is just that - an argument

GCC - unix/linux compiler, MinGW - approximation of GCC on Windows environment, Microsoft compiler and Intel compiler - more of the same as names suggest(both produce much , much better programs on Windows then MinGW, btw)

CC BY-SA 3.0
5
  • @rubenvb - enlighten me, please
    – Real Name
    Commented May 24, 2016 at 13:10
  • 2
    MinGW doesn't provide a linux-like environment, that is MSYS(2) and/or Cygwin. MinGW provides headers and libraries so that GCC (a compiler suite, not just a "unix/linux compiler") can be built and used against the Windows C runtime. It provides sporadic extensions, mostly where the C and/or C++ standards require additional functionality that hasn't been implemented in Windows' versions of the C library (think C11 currently). MinGW is not "an approximation" of GCC on Windows. It is rather feature-complete. The reasons for its existence don't fit into this little box anymore.
    – rubenvb
    Commented May 24, 2016 at 13:17
  • @rubenvb what c++ 11(or 14 for that matter) functionality does it provide, that MS compiler does not ? Did you ever encounter usage of MinGW without Cygwin? What is the reason you need to use the named header files on windows, and how does it contradict anything I said? As a person who does NATIVE development on Windows , Linux and Mac I am really , really curious - for 10 years or so , I am yet to hear a comprehensive answer
    – Real Name
    Commented May 24, 2016 at 13:36
  • before VS2015 (and even in the current VS2015, see here), there are various things missing or badly implemented where GCC and Clang both have correct implementations. VS generally lags behind in standards conformance. This has been so since GCC 4.7 came out. I (and e.g. Qt Open Source) use MinGW-w64 without Cygwin. I don't understand what you mean by "named header files". GCC with MinGW-w64 is just another compiler on Windows, and useful as such, outside of any licensing limitations VS comes with.
    – rubenvb
    Commented May 24, 2016 at 13:53
  • "MinGW provides headers headers and libraries so that GCC" - that is what I mean . On C++ compliance I stand corrected - I don't care much for it (especially C++14) myself . What I should have written "linux developers, funboys of c++14/17 and people who like the over-complicated way of development" - thank you for correcting me . Licencing limitation of MSVC- I am not familiar with them , using community edition you can pretty much compile everything outside of VS(which is just an IDE)
    – Real Name
    Commented Jul 13, 2016 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.