MinGW:安装gcc、g++
1.MinGW是什么?
wiki:https://en.wikipedia.org/wiki/MinGW
MinGW (“Minimalist GNU for Windows”), formerly mingw32, is a free and open source software development environment to create Microsoft Windows applications.
简单来说,MinGW是一系列工具集合,包括类似yum、rpm的库/包管理功能。
The development of the MinGW project has been forked with the creation in 2005–2008 of an alternative project called Mingw-w64.
MinGW有一个fork版本,即Mingw-w64。(同时支持32bit和64bit)
MinGW includes a port of the GNU Compiler Collection (GCC), GNU Binutils for Windows (assembler, linker, archive manager), a set of freely distributable Windows specific header files and static import libraries which enable the use of the Windows API, a Windows native build of the GNU Project’s GNU Debugger, and miscellaneous utilities.
MinGW包括的内容,有gcc编译器、链接器、头文件等。
MinGW can be run either on the native Microsoft Windows platform, cross-hosted on Linux (or other Unix), or “cross-native” on Cygwin. Although programs produced under MinGW are 32-bit executables, they can be used both in 32 and 64-bit versions of Windows.
注意:基于MinGW生成的可执行文件都是32bit的。
2.MinGW怎么装?
2.1.安装目录
D:\app\MinGW
2.2.下载文件
https://sourceforge.net/projects/mingw/
mingw-get-setup.exe
2.3.安装 MinGW Installation Manager
注意,选择安装目录为:D:\app\MinGW
安装中…
点击:Continue
安装成功后,将会自动打开 MinGW Installation Manager:
此时,MinGW/bin中仅有mingw-get.exe。
EB@DESKTOP-K45IA6V MINGW64 /d/app
$ ll MinGW/
total 0
drwxr-xr-x 1 EB 197609 0 Jun 22 14:58 bin/
drwxr-xr-x 1 EB 197609 0 Jun 22 14:58 libexec/
drwxr-xr-x 1 EB 197609 0 Jun 22 14:58 share/
drwxr-xr-x 1 EB 197609 0 Jun 22 14:58 var/
EB@DESKTOP-K45IA6V MINGW64 /d/app
$ ll MinGW/bin
total 52
-rwxr-xr-x 1 EB 197609 52224 Oct 5 2013 mingw-get.exe*
2.4.安装 gcc、g++等库/包
选中所有的package:
点击左上角Installation:Apply Changes,进行安装:
安装完成,关闭对话窗口:
此时,MinGW\bin中包含我们常见的:
c++.exe、cpp.exe、g++.exe、gcc.exe、gdb.exe、ld.exe、nm.exe、objdump.exe等等。
$ ll c++.exe cpp.exe g++.exe gcc.exe gdb.exe ld.exe nm.exe objdump.exe
-rwxr-xr-x 1 EB 197609 997902 May 30 2017 c++.exe*
-rwxr-xr-x 1 EB 197609 996366 Jul 25 2017 cpp.exe*
-rwxr-xr-x 1 EB 197609 997902 May 30 2017 g++.exe*
-rwxr-xr-x 1 EB 197609 995342 Jul 25 2017 gcc.exe*
-rwxr-xr-x 1 EB 197609 30595068 Sep 15 2013 gdb.exe*
-rwxr-xr-x 1 EB 197609 1291278 May 22 2017 ld.exe*
-rwxr-xr-x 1 EB 197609 978958 May 22 2017 nm.exe*
-rwxr-xr-x 1 EB 197609 1756174 May 22 2017 objdump.exe*
2.5.配置环境变量PATH
将D:\app\MinGW\bin添加到环境变量PATH中:
控制面板\系统和安全\系统->高级系统设置->环境变量->用户变量->编辑变量PATH:
新增路径D:\app\MinGW\bin,然后确认保存即可。
3.MinGW测试使用
Microsoft Windows [版本 10.0.17763.107]
(c) 2018 Microsoft Corporation。保留所有权利。
C:\Users\EB>where gcc g++
D:\app\MinGW\bin\gcc.exe
D:\app\MinGW\bin\g++.exe
C:\Users\EB>gcc --version
gcc (MinGW.org GCC-6.3.0-1) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
C:\Users\EB>g++ --version
g++ (MinGW.org GCC-6.3.0-1) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
4.MinGW安装常见问题?
4.1.报错1
mingw-get: *** ERROR *** http://prdownloads.sourceforge.net/mingw/mingw-get-0.6.2-mingw32-beta-20131004-1-bin.tar.xz?download:cannot open URL
解决方法:科学上网。
4.2.报错2
解决方法:科学上网。