MinGW,Minimalist GNU for Windows,windows最简化的GNU,就是一个C的编译工具集,转为windows操作系统下的C/C++开发者服务。我们从官网下载安装程序,打开官网后右边菜单栏点击Downloads:
跳往下载列表页面后,往下拉,点击安装程序下载:
最后双击该exe执行安装,弹出安装界面:
接下来默认给你设置好了安装目录和勾选了默认设置,点击继续:
最后进入安装包阶段,左边窗口有两个按钮:基础必备的和全部的,对应右边的详细列表:
点击复选框,下面窗口会说明这个包用来干嘛, 在弹出的框中点击Mark for Installation安装标记后,点击左上角的Installation -> Apply Changes:
虽然只是这几个基础包,下载也不容易,毕竟是外网,老是链接超时:
而且它会反复尝试,退不出来,只能用任务管理器把它kill掉。既然此路不通,只能另走他路。我们打开命令行,进入C盘的MinGW目录bin路径,敲命令安装:
C:\MinGW\bin>mingw-get install gcc
http://osdn.net/dl/mingw/gcc-9.2.0-2-mingw32-lic.tar.xz
21.33 kB / 21.33 kB |================================================| 100%
http://osdn.net/dl/mingw/libiconv-1.14-4-mingw32-dll-2.tar.xz
642.41 kB / 642.41 kB |================================================| 100%
http://osdn.net/dl/mingw/libatomic-9.2.0-2-mingw32-dll-1.tar.xz
7.47 kB / 7.47 kB |================================================| 100%
http://osdn.net/dl/mingw/libgcc-9.2.0-2-mingw32-dll-1.tar.xz
167.01 kB / 167.01 kB |================================================| 100%
http://osdn.net/dl/mingw/libgmp-6.1.2-3-mingw32-dll-10.tar.xz
204.25 kB / 204.25 kB |================================================| 100%
如果还是出现链接下载失败:
http://osdn.net/dl/mingw/gcc-9.2.0-2-mingw32-lang.tar.xz
1.57 MB / 1.57 MB |================================================| 100%
mingw-get: *** ERROR *** http://osdn.net/dl/mingw/gcc-core-9.2.0-2-mingw32-bin.tar.xz:cannot open URL; status = 12029
mingw-get: *** ERROR *** Get package: http://osdn.net/dl/mingw/gcc-core-9.2.0-2-mingw32-bin.tar.xz: download failed
install: gcc-9.2.0-2-mingw32-lic.tar.xz
我们重新执行一次即可,它会把失败的jar包重新下载:
C:\MinGW\bin>mingw-get install gcc
http://osdn.net/dl/mingw/gcc-core-9.2.0-2-mingw32-bin.tar.xz
17.05 MB / 17.05 MB |================================================| 100%
install: gcc-9.2.0-2-mingw32-lic.tar.xz
mingw-get: *** ERROR *** package gcc-9.2.0-2-mingw32-lic.tar.xz is already installed
install: gcc-core-9.2.0-2-mingw32-bin.tar.xz
installing gcc-core-9.2.0-2-mingw32-bin.tar.xz
install: gcc-core-4.8.2-2-mingw32-dev.tar.lzma
mingw-get: *** ERROR *** package gcc-core-4.8.2-2-mingw32-dev.tar.lzma is already installed
install: gcc-core-4.8.1-5-mingw32-doc.tar.lzma
mingw-get: *** ERROR *** package gcc-core-4.8.1-5-mingw32-doc.tar.lzma is already installed
install: gcc-9.2.0-2-mingw32-man.tar.xz
mingw-get: *** ERROR *** package gcc-9.2.0-2-mingw32-man.tar.xz is already installed
install: gcc-9.2.0-2-mingw32-info.tar.xz
mingw-get: *** ERROR *** package gcc-9.2.0-2-mingw32-info.tar.xz is already installed
install: gcc-9.2.0-2-mingw32-lang.tar.xz
mingw-get: *** ERROR *** package gcc-9.2.0-2-mingw32-lang.tar.xz is already installed
同上,继续执行g++、gdb和mingw32-make的下载:
C:\MinGW\bin>mingw-get install g++
http://osdn.net/dl/mingw/gcc-c++-9.2.0-2-mingw32-bin.tar.xz
10.39 MB / 10.39 MB |================================================| 100%
http://osdn.net/dl/mingw/gcc-c++-9.2.0-2-mingw32-man.tar.xz
255.52 kB / 255.52 kB |================================================| 100%
C:\MinGW\bin>mingw-get install gdb
http://osdn.net/dl/mingw/libz-1.2.11-1-mingw32-dll-1.tar.xz
62.95 kB / 62.95 kB |================================================| 100%
最后把MinGW配置到系统环境变量中,方便使用以上工具:右键点击“此电脑” -> 选择“属性” -> 选“高级系统设置” -> 点“环境变量” -> 选“Path”后点编辑 -> 在弹出框点新建,把C:\MinGW\bin的路径加进去:
确认下我们的安装:
C:\Users\wuxun>gcc -v COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/9.2.0/lto-wrapper.exe gcc 版本 9.2.0 (MinGW.org GCC Build-2) C:\Users\wuxun>g++ -v COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/9.2.0/lto-wrapper.exe gcc 版本 9.2.0 (MinGW.org GCC Build-2)