不同操作系统下的C-C++编译器
1 Windows系统
1) MSVC
指微软的VC编译器,the Microsoft Visual C++ compiler and libraries toolset
2) MinGW
Minimalist GNU on Windows的缩写。允许你在GNU/Linux和Windows平台⽣成本地的Windows程序⽽不需要第三⽅C运⾏时库。
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).
Primarily intended for use by developers working on the native MS-Windows platform, but also available for cross-hosted use, (see note below -- you may need to follow the "" link to see it), MinGW includes:
A port of the GNU Compiler Collection (GCC), including C, C++, ADA and Fortran compilers;
GNU Binutils for Windows (assembler, linker, archive manager)
A command-line installer, with optional GUI front-end, (mingw-get) for MinGW and MSYS deployment on MS-Windows
A GUI first-time setup tool (mingw-get-setup), to get you up and running with mingw-get.
MSYS, a contraction of "Minimal SYStem", is a Bourne Shell command line interpreter system. Offered as an alternative to Microsoft', this provides a general purpose command line environment, which is particularly suited to use with MinGW, for porting of many Open Source applications to the MS-Windows platform; a light-weight fork of Cygwin-1.3, it includes a small selection of Unix tools, chosen to facilitate that objective.
⽹友: mingw 中的 gcc 相当于⼀个交叉编译器,输出exe ,⽽不是 ELF。
⽹上:
MinGW, formerly mingw32, is a distribution of the GNU Compiler Collection and GNU Binutils for use in compiling native Microsoft Windows applications.  It carries along a set of freely distributable header files and static import libraries to enable use of the Windows API. MinGW can function either as a cross compiler targeting Windows or as a self-hosted toolchain which can be run on Windows itself.
3) TMD-GCC
A compiler suite for Windows. It combines the most recent stable release of the toolset, a few patches for Windows-friendliness, and the free and open-source or runtime APIs to create an open-source alternative to Microsoft's compiler and platform SDK.
4)Mingw-w64
Mingw-w64 is an advancement of the project, created to support the GCC compiler on Windows systems. It has forked it in 2007 in order to provide support for 64 bits and new APIs.
2 Unix系统
1) GCC (⽀持各种语⾔的编译,编译器的集合)
GCC(GNU Compiler Collection,GNU编译器套件),是由 GNU 开发的编程语⾔编译器。它是以许可证所发⾏的⾃由软件,也是 GNU 计划的关键部分。GCC原本作为GNU操作系统的官⽅编译器,现已被⼤多数类操作系统(如、、等)采纳为标准的
GCC 原名为 GNU C 语⾔编译器(GNU C Compiler),因为它原本只能处理 。GCC 很快地扩展,变得可处理 。后来⼜扩展能够⽀持更多编程语⾔,如、、、、、以及各类上的等,所以改名GNU编译器套件(GNU Compiler Collection)。
知乎:
The GNU Compiler Collection includes front ends for , , Objective-C, , Ada, Go, and D, as well as libraries for these languages (libstdc++,...). GCC was originally written as the compiler for the . The GNU system was developed to be 100% free software, free in the sense that it .
We strive to provide regular, high quality , which we want to work well on a variety of native and cross t
argets (including GNU/Linux), and encourage everyone to changes or help GCC. Our sources are readily and freely available via and weekly .
Major decisions about GCC are made by the , guided by the .
GCC: Several versions of the compiler (C, C++, Objective-C, Ada, Fortran, Java and treelang) are integrated; this is why we use the name “GNU Compiler Collection”. GCC can compile programs written in any of these languages.
When referring to C++ compilation, it is usual to call the compiler “G++ (终于知道了GCC与g++关系)”. Since there is only one compiler, it is also accurate to call it “GCC” no matter what the language context; however, the term “G++” is more useful when the emphasis is on compiling C++ programs.  Similarly, when we talk about Ada compilation, we usually call the compiler “GNAT”, for the same reasons.
We use the name “GCC” to refer to the compilation system as a whole, and more specifically to the language-independent part of the compiler.
这篇⽂章从细节上讲了安装GCC后在命令⾏中使⽤gcc,g++命令的细节上的不同:
Others:
windows下安装MinGW
3.  C/C++的编译器|编译环境(⾮常全⾯的⽐较)---知乎
c语言编译器怎么用不了C/C++编译器的⼀些易混淆概念,总结⼀下。
关于什么是Unix-like操作系统,常见操作系统间差异,什么是操作系统接⼝等等,请参考《》。
C/C++编译器有哪些?
⾸先是如雷贯⽿的这⼏位仁兄,MSVC、GCC、Cygwin、MingW(),另外还有些⼩众和新秀,像ICC(Intel C/C++ Compiler)、
⾸先是如雷贯⽿的这⼏位仁兄,MSVC、GCC、Cygwin、MingW(),另外还有些⼩众和新秀,像ICC(Intel C/C++ Compiler)、BCC(Borland C/C++ Compiler,快销声匿迹了)、RVCT(ARM的汇编/C/C++编译器,内置在ARM的IDE——RVDS中)、Pgi编译器……其实有⼀⼤串,我们只要熟悉常⽤的最强⼤的⼏款就可以了。
主流C/C++编译器|编译环境简介
MSVC
MSVC是微软Windows平台Visual Studio⾃带的C/C++编译器。
优点:对Windows平台⽀持好,编译快。
缺点:对C++的新标准⽀持得少。
GCC
GCC原名GNU C Compiler,后来逐渐⽀持更多的语⾔编译(C++、Fortran、Pascal、Objective-C、Java、Ada、Go等),所以变成了GNU Compiler Collection(GNU编译器套装),是⼀套由GNU⼯程开发的⽀持多种编程语⾔的编译器。GCC是⾃由软件发展过程中的著名例⼦,由⾃由软件基⾦会以GPL协议发布,是⼤多数类Unix(如Linux、BSD、Mac OS X等)的标准编译器,⽽且适⽤于
Windows(借助其他移植项⽬实现的,⽐如MingW、Cygwin等)。GCC⽀持多种计算机体系芯⽚,如x86、ARM,并已移植到其他多种硬件平台。
优点:类Unix下的标准编译器,⽀持众多语⾔,⽀持交叉编译。
缺点:默认不⽀持Windows,需要第三⽅移植才可⽤于Windows。
Cygwin
Cygwin是⼀个Windows下Unix-like模拟环境,具体说就是Unix-like接⼝(OS API,命令⾏)重定向层,其⽬的是不修改软件源码仅重新编译就可以将Unix-like系统上的软件移植到Windows上(这个移植也许还算不上严格意义上的⽆缝移植)。始于1995年,最初作为Cygnus软件公司⼯程师Steve Chamberlain的⼀个项⽬。
和GCC的关系:Cygwin是让Windows拥有Unix-like环境的软件⽽不是编译器,GCC是安装在Cygwin上的编译器。
优点:可以⽐MingW移植更多的软件到Windows上,对Linux接⼝模拟⽐MingW全⾯。
缺点:软件运⾏依赖cygwin1.dll,速度受点影响。
注意:Unix-like模拟环境不是Unix虚拟环境,很多论述中都声称Cygwin是在Windows上尽可能模拟类Unix环境,这容易造成误解,好像类Unix的elf程序可以直接运⾏在安装了Cygwin的Windows上⼀样。Cygwin和Wine的思路是不同的。在Windows+Cygwin上你可以像类Unix那样使⽤命令⾏和编程,但elf等⾮exe格式的程序是不能被Cygwin运⾏的,所以Cygwin和Unix虚拟机、Wine是完全不同的,叫Unix-like环境,模拟⾮虚拟,是有限的选择性的模拟,请不要误解。
MingW
MingW(Minimalist GNU on Windows)是⼀个Linux/Windows下的可以把软件源码中Unix-like OS API调⽤通过头⽂件翻译替换成相应的Windows API调⽤的编译环境,其⽬的和Cygwin相同。从⽽把Linux上的软件在不修改源码的情况下编译为可直接在Win下执⾏的exe。
和GCC的关系:MingW是编译环境,不是编译器,GCC是MingW中的核⼼组成。
优点:在Win下可以和Linux⼀样的⽅式编译C/C++源码,可以说是Win版的GCC,其⽣产的Windows PE程序相⽐Cygwin不依赖任何第三⽅库,⽐Cygwin纯粹,理论上也更快速。
缺点:编译速度、编译出的程序在算法上可能都⽐MSVC慢。
注意:与Windows下其它编译器不同的是,MinGW与Linux下⼴泛使⽤的GNU近乎完全兼容,这意味着,在Linux下如何编译源代码,在MinGW中也可以以完全相同的⽅式编译。有些Linux下的开发⼈员(⽐如开源阵营)发布的源代码通常只提供Linux下的编译⽅式,⽽不提供Windows下的编译⽅式(这可能与其不熟悉windows操作系统有关),但确实有不少⽤户需要在在Windows下编译使⽤此源代码。这在种情况下,如果Windows⽤户想⽤VC、BC等编译器编译该源代码,必须重写Makefile(各种编译器所⽀持的Makefile不尽相同),⼯作量⽐较⼤不说,还很难保证不出错。MinGW的出现,提供了两个平
台下的“跨平台编译⽅案”。MinGW与MSYS相配合,连./configure 都有了。与GNU不同的是,MinGW编译⽣成的是Windows下的可执⾏⽂件(.exe)或库⽂件(.dll,.lib)——不过编译过程中的的中间⽂件仍然是.o⽂件,⽽不是.obj⽂件(这当然⽆所谓了,中间⽂件嘛,编译完成后就没有⽤了)。
在我们对⽐Cygwin和MingW之前,请先理清⼀件事,那就是,
如何从Unix-like系统向Windows系统移植软件?
现代操作系统包括Windows和Linux的基本设计概念,像进程线程地址空间虚拟内存这些都⼤同⼩异,⼆者之上的程序之所以不兼容,主要
现代操作系统包括Windows和Linux的基本设计概念,像进程线程地址空间虚拟内存这些都⼤同⼩异,⼆者之上的程序之所以不兼容,主要是它们对这些功能具体实现上的差异:
⾸先,是可执⾏⽂件的格式,Window使⽤PE的格式,并且要求以.EXE为后缀名,Linux则使⽤Elf。
其次,操作系统API也同,⽐如,Windows⽤CreateProcess()创建进程,⽽Unix-like系统则使⽤fork(),其他还有很多诸如spawn、signals、select、sockets等。
分析之后可知,要把Unix-like系统上的软件移植到Windows上,有⼏种思路:
第⼀种:修改软件源码并重新编译,这个⽅法最笨,类Unix下⼤量的软件要修改⼯作量很⼤,编译⽣成⽬标平台可执⾏⽂件格式。
第⼆种:不修改软件源码但把类Unix接⼝调⽤悄悄替换为WinAPI,还是需要重新编译,编译⽣成⽬标平台可执⾏⽂件格式。
第三种,⽆缝移植的运⾏环境,⽆需重新编译,在⼀种OS上建⽴另⼀中OS的应⽤软件虚拟环境(和虚拟机不⼀样),⽐如Wine(把Windows上的可执⾏程序直接原样移植到Linux上)。
Cygwin和MingW的对⽐
作为编译环境时,都依赖于GCC
⽤它们作编译环境、交叉编译,根本上都是因为GCC编译器的⽀持,它们做的⼯作是为GCC的编译扫除Unix-like、Windows间OS API的差异这个障碍。
⼆者都必须重新编译后实现移植,⽣成的程序都是PE格式
⼆者都不能让Linux下的程序直接运⾏在Windows上(⽆缝移植),必须通过源代码重新编译。有些⼈声称cygwin⽀持rpm的压缩包,注意,rpm压缩包其实是src.rpm,内部还是源码⽽⾮elf格式,cygwin不⽀持常规rpm包的安装。
Cygwin运⾏在Windows上,MingW运⾏在Linux或者Windows上
Cygwin是Windows上运⾏的Unix-like环境,MingW是运⾏在Linux或者Windows上的Windows PE编译环境。
MingW中的⼦项⽬MSys和Cygwin更像
Cygwin除了全⾯模拟Linux的接⼝(命令⾏,OS API),提供给运⾏在它上⾯的的Windows程序使⽤,并提供了⼤量现成的软件,更像是⼀个平台。MingW也有⼀个叫MSys(Minimal SYStem)的⼦项⽬,主要是提供了⼀个模拟Linux的Shell和⼀些基本的Linux⼯具。因为编译⼀个⼤型程序,光靠⼀个GCC是不够的,还需要有Autoconf等⼯具来配置项⽬,所以⼀般在Windows下编译ffmpeg等Linux下的⼤型项⽬都是通过Msys来完成的,当然Msys只是⼀个辅助环境,根本的⼯作还是MingW来做的。
实现思路有同有异
Cygwin和MingW都是第⼆种软件移植思路,当然,⼆者还是有区别,区别就在于“替换”⽅式,Cygwin编译时,程序依然以Linux的⽅式调⽤系统API,只不过把Unix-like接⼝link到⾃⼰的cygwin1.dll上,然后在cygwin1.dll中重新调⽤Windows API,cygwin1.dll再调⽤Windows对应的实现,来把结果返回给程序。也就是说,他们基于Win32 API中写了⼀个Unix系统API的重定向层,所以⽤它移植的软件都依赖于cyg
win1.dll,MingW编译时通过特有的WinAPI头⽂件把类Unix-like调⽤替换为WinAPI,⽤它移植的软件⽆需依赖第三⽅库,可直接运⾏在Windows平台。为了达到类Unix软件仅通过重新编译移植到Win的⽬的,Cygwin在运⾏时偷梁换柱,MingW在编译时偷梁换柱。
⽤⼀个PE格式查看⼯具检查⼀下就能发现,Cygwin⽣成的程序依然有fork()这样的Linux系统调⽤,但⽬标库是cygwin1。⽽MingW⽣成的程序,则全部使⽤从KERNEL32导出的标准Windows系统API。
使⽤⽅式有同有异
把类Unix上的软件移植到Windows是⼆者的主要⽬标,除此之外,顺带的,MingW和Cygwin都可以⽤来跨平台开发等等其他事情,Windows + Cygwin:可以在Windows上学习Linux命令,还可以在Windows上做Linux软件的开发,包括⽤GCC编译elf(交叉编译)。Linux + MingW:可以在Linux上做Windows软件的开发,包括⽤GCC编译exe(交叉编译)。
Windows/Linux + MingW:可以摆脱MSVC的“束缚”,⽤GNU的⾃由软件来编译⽣成不依赖第三⽅库的纯粹Windows PE格式(exe)⼆进制程序。
Cygwin重量级,MingW轻量级
与MingW思路⼀致的,两者相⽐,Cygwin是重量级的(需下载50M以上直⾄数百兆不等,安装后占⽤空
间可达1G),MinGW是轻量级的(需下载的⽂件只有20M,安装后70M左右),这是单纯从体积上说的,另外Cygwin现在据说也不是完全免费的了。
⽹络上的对⽐列表(UnxUtils⾃⾏⽆视,仅供参考)
功能UnxUtilsMinGWCygwin设计原理原⽣原⽣模拟运⾏依赖⽆依赖依赖msys.dll(⼀定依赖它吗?值得验证)依赖cygwin.dll运⾏性能(⽐较)最快中等慢DOS执⾏可以可以不可以更新速度完善停⽌更新较慢基本同步gccshell命令较多较少较多
unameWindowsNTMINGW32_NT-5.1CYGWIN_NT-5.1env同Windows同Windows不完全同
WindowsrootC:/C://homeC:/Documents and Settings/test/home/test: No such file or
WindowsrootC:/C://homeC:/Documents and Settings/test/home/test: No such file or
directory/home/testpwdC:/bin/usr/bin/home/testdfcannot read table of mounted filesystems⽆/cygdrive/cvi⽆⽆有gcc套件⽆有有开发库⽆WinAPIPOSIX图形库⽆GTK/QTGTK/QT可移植性⽆Win32API不可移植⽆缝移植程序运⾏⽆原⽣模拟程序依赖⽆⽆cygwin.dll程序性能(⽐较)⽆较快(慢于VC和Linux下的gcc)较慢(快于java)