一、MinGW-W64的介绍和官网

Mingw-w64 is an advancement of the original mingw.org 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. It has since then gained widespread use and distribution.

简而言之:MinGW-W64包含了一些组件,这些组件是运行C、C++程序所必须的。

二、直接安装法(最常见)

从SourceForge 下载MinGW-W64

SourceForge 是全球最大的开放源代码软件开发平台和仓库。它集成了很多开放源代码应用程序,为软件开发提供了整套生命周期服务。SourceForge.net是开放源代码软件的开发者进行开发管理的集中式场所,也是源代码仓库。

1、 通过MinGW-W64 Online Installer下载安装
Online Installer是在线安装,受限于中国的网络,不推荐使用这种方法。
2、 下载离线压缩包,解压后使用。
”Pre-built toolchains and packages“推荐:MinGW W64 GCC-8.1.0 x86_64 posix seh

posix对比win32 特定情况下的性能下降,但是功能更全,并且支持跨平台 seh对比sjlj 版本更新(不支持32位程序)。

三、通过MSYS2 安装 MinGW(GCC版本最新)

MSYS2 is a collection of tools and libraries providing you with an easy-to-use environment for building, installing and running native Windows software. MSYS2 (Minimal SYStem 2) is an independent rewrite of MSYS, a (command-line) shell for development usage, and based on modern Cygwin (POSIX compatibility layer) and MinGW-w64 (from “MinGW-builds”), with the aim of better interoperability with native Windows software.

MSYS2安装方便、自带 Pacman 管理、软件和库较全较新、中文支持好。
简而言之:MSYS2对比单独的MinGW功能更全、更新、更强大。强烈推荐

1、 官网下载并安装MSYS2

2、 修改Pacman文件为国内源

软件包管理器Pacman默认的源,下载速度太慢,建议修改为国内的。
进入MSYS2安装目录找到Pacman.d文件夹,修改里面3个文件的内容。
image.png
如何修改:
官方教程-镜像使用帮助(任选其一使用):
还是不会:
下面的文件已经配置了MSYS2的清华源,下载解压后、拖动并替换原来的文件。即可完成配置。
pacman.d.zip

3、 安装相关组件并配置

效果图:
image.png
命令
中文网上流传的教程都是**不合的,现在只需要一条命令就可以完成CLion和MSYS2的配置。**

  1. # 刷新软件包数据(将本地包数据库与远程仓库进行同步)
  2. pacman -Sy
  3. # MSYS2 MSYS可能需要重启来更新组件,若重启,则再次运行上面的命令。
  4. # 安装 MinGW 工具链的全部
  5. pacman -S mingw-w64-x86_64-toolchain
  6. # 更新全部 (Update the package database and core system packages)
  7. pacman -Syu
  8. # 以后更新软件,执行该命令即可;若重启,再次执行即可。

具体细节:
MSYS2 安装大小450M
MinGW 工具链大小150M、安装大小900M
安装总大小1400M,占用空间1500M、

  1. Administrator@WinSer-ALYPC MSYS ~
  2. # pacman -Syu
  3. :: 正在同步软件包数据库...
  4. mingw32 已经是最新版本
  5. mingw64 已经是最新版本
  6. msys 已经是最新版本
  7. :: Starting core system upgrade...
  8. 今日无事可做
  9. :: 正在进行全面系统更新...
  10. 今日无事可做
  11. Administrator@WinSer-ALYPC MSYS ~
  12. # pacman -S mingw-w64-x86_64-toolchain
  13. :: 在组 mingw-w64-x86_64-toolchain 中有 17 成员:
  14. :: 软件仓库 mingw64
  15. 1) mingw-w64-x86_64-binutils 2) mingw-w64-x86_64-crt-git 3) mingw-w64-x86_64-gcc 4) mingw-w64-x86_64-gcc-ada 5) mingw-w64-x86_64-gcc-fortran
  16. 6) mingw-w64-x86_64-gcc-libgfortran 7) mingw-w64-x86_64-gcc-libs 8) mingw-w64-x86_64-gcc-objc 9) mingw-w64-x86_64-gdb 10) mingw-w64-x86_64-headers-git
  17. 11) mingw-w64-x86_64-libmangle-git 12) mingw-w64-x86_64-libwinpthread-git 13) mingw-w64-x86_64-make 14) mingw-w64-x86_64-pkg-config 15) mingw-w64-x86_64-tools-git
  18. 16) mingw-w64-x86_64-winpthreads-git 17) mingw-w64-x86_64-winstorecompat-git
  19. 输入某个选择 ( 默认=全部选定 ):
  20. 正在解析依赖关系...
  21. 正在查找软件包冲突...
  22. 软件包 (45) mingw-w64-x86_64-bzip2-1.0.8-1 mingw-w64-x86_64-ca-certificates-20200601-1 mingw-w64-x86_64-expat-2.2.9-1 mingw-w64-x86_64-gettext-0.19.8.1-9
  23. mingw-w64-x86_64-gmp-6.2.0-1 mingw-w64-x86_64-isl-0.22.1-1 mingw-w64-x86_64-libffi-3.3-1 mingw-w64-x86_64-libiconv-1.16-1
  24. mingw-w64-x86_64-libsystre-1.0.1-4 mingw-w64-x86_64-libtasn1-4.16.0-1 mingw-w64-x86_64-libtre-git-r128.6fb7206-2 mingw-w64-x86_64-mpc-1.2.0-1
  25. mingw-w64-x86_64-mpdecimal-2.5.0-1 mingw-w64-x86_64-mpfr-4.1.0-2 mingw-w64-x86_64-ncurses-6.2-2 mingw-w64-x86_64-openssl-1.1.1.h-1
  26. mingw-w64-x86_64-p11-kit-0.23.20-2 mingw-w64-x86_64-python-3.8.6-3 mingw-w64-x86_64-readline-8.0.004-1 mingw-w64-x86_64-sqlite3-3.33.0-1
  27. mingw-w64-x86_64-tcl-8.6.10-1 mingw-w64-x86_64-termcap-1.3.1-6 mingw-w64-x86_64-tk-8.6.10-2 mingw-w64-x86_64-windows-default-manifest-6.4-3
  28. mingw-w64-x86_64-xxhash-0.7.4-1 mingw-w64-x86_64-xz-5.2.5-1 mingw-w64-x86_64-zlib-1.2.11-7 mingw-w64-x86_64-zstd-1.4.5-1 mingw-w64-x86_64-binutils-2.35.1-2
  29. mingw-w64-x86_64-crt-git-8.0.0.6001.98dad1fe-1 mingw-w64-x86_64-gcc-10.2.0-3 mingw-w64-x86_64-gcc-ada-10.2.0-3 mingw-w64-x86_64-gcc-fortran-10.2.0-3
  30. mingw-w64-x86_64-gcc-libgfortran-10.2.0-3 mingw-w64-x86_64-gcc-libs-10.2.0-3 mingw-w64-x86_64-gcc-objc-10.2.0-3 mingw-w64-x86_64-gdb-9.2-3
  31. mingw-w64-x86_64-headers-git-8.0.0.6001.98dad1fe-1 mingw-w64-x86_64-libmangle-git-8.0.0.6001.98dad1fe-1
  32. mingw-w64-x86_64-libwinpthread-git-8.0.0.6001.98dad1fe-3 mingw-w64-x86_64-make-4.3-1 mingw-w64-x86_64-pkg-config-0.29.2-2
  33. mingw-w64-x86_64-tools-git-8.0.0.6001.98dad1fe-1 mingw-w64-x86_64-winpthreads-git-8.0.0.6001.98dad1fe-3
  34. mingw-w64-x86_64-winstorecompat-git-8.0.0.6001.98dad1fe-1
  35. 下载大小: 132.29 MiB
  36. 全部安装大小: 904.19 MiB
  37. :: 进行安装吗? [Y/n] Y
  38. :: 正在获取软件包......
  39. mingw-w64-x86_64-binutils-2.35.1-2-any 9.6 MiB 19.7 MiB/s 00:00 [############################################################] 100%
  40. mingw-w64-x86_64-headers-git-8.0.0.6001.98dad1fe-1-any 5.1 MiB 165 MiB/s 00:00 [############################################################] 100%
  41. mingw-w64-x86_64-crt-git-8.0.0.6001.98dad1fe-1-any 3.1 MiB 102 MiB/s 00:00 [############################################################] 100%
  42. mingw-w64-x86_64-isl-0.22.1-1-any 642.1 KiB 0.00 B/s 00:00 [############################################################] 100%
  43. mingw-w64-x86_64-gmp-6.2.0-1-any 490.8 KiB 0.00 B/s 00:00 [############################################################] 100%
  44. mingw-w64-x86_64-mpfr-4.1.0-2-any 357.1 KiB 0.00 B/s 00:00 [############################################################] 100%
  45. mingw-w64-x86_64-mpc-1.2.0-1-any 72.8 KiB 0.00 B/s 00:00 [############################################################] 100%
  46. mingw-w64-x86_64-libwinpthread-git-8.0.0.6001.98dad1fe-3-any 29.3 KiB 0.00 B/s 00:00 [############################################################] 100%
  47. mingw-w64-x86_64-gcc-libs-10.2.0-3-any 756.3 KiB 0.00 B/s 00:00 [############################################################] 100%
  48. mingw-w64-x86_64-windows-default-manifest-6.4-3-any 12.9 KiB 0.00 B/s 00:00 [############################################################] 100%
  49. mingw-w64-x86_64-winpthreads-git-8.0.0.6001.98dad1fe-3-any 39.9 KiB 0.00 B/s 00:00 [############################################################] 100%
  50. mingw-w64-x86_64-zstd-1.4.5-1-any 480.5 KiB 0.00 B/s 00:00 [############################################################] 100%
  51. mingw-w64-x86_64-gcc-10.2.0-3-any 25.2 MiB 21.5 MiB/s 00:01 [############################################################] 100%
  52. mingw-w64-x86_64-gcc-ada-10.2.0-3-any 18.7 MiB 11.7 MiB/s 00:02 [############################################################] 100%
  53. mingw-w64-x86_64-gcc-libgfortran-10.2.0-3-any 777.6 KiB 12.2 MiB/s 00:00 [############################################################] 100%
  54. mingw-w64-x86_64-gcc-fortran-10.2.0-3-any 10.1 MiB 10.9 MiB/s 00:01 [############################################################] 100%
  55. mingw-w64-x86_64-gcc-objc-10.2.0-3-any 11.2 MiB 24.0 MiB/s 00:00 [############################################################] 100%
  56. mingw-w64-x86_64-expat-2.2.9-1-any 141.3 KiB 0.00 B/s 00:00 [############################################################] 100%
  57. mingw-w64-x86_64-gettext-0.19.8.1-9-any 3.4 MiB 43.3 MiB/s 00:00 [############################################################] 100%
  58. mingw-w64-x86_64-libtre-git-r128.6fb7206-2-any 84.2 KiB 0.00 B/s 00:00 [############################################################] 100%
  59. mingw-w64-x86_64-libsystre-1.0.1-4-any 24.0 KiB 0.00 B/s 00:00 [############################################################] 100%
  60. mingw-w64-x86_64-ncurses-6.2-2-any 1578.1 KiB 103 MiB/s 00:00 [############################################################] 100%
  61. mingw-w64-x86_64-bzip2-1.0.8-1-any 88.6 KiB 0.00 B/s 00:00 [############################################################] 100%
  62. mingw-w64-x86_64-libffi-3.3-1-any 55.7 KiB 0.00 B/s 00:00 [############################################################] 100%
  63. mingw-w64-x86_64-mpdecimal-2.5.0-1-any 344.4 KiB 0.00 B/s 00:00 [############################################################] 100%
  64. mingw-w64-x86_64-libtasn1-4.16.0-1-any 172.0 KiB 0.00 B/s 00:00 [############################################################] 100%
  65. mingw-w64-x86_64-p11-kit-0.23.20-2-any 293.8 KiB 0.00 B/s 00:00 [############################################################] 100%
  66. mingw-w64-x86_64-ca-certificates-20200601-1-any 349.7 KiB 21.3 MiB/s 00:00 [############################################################] 100%
  67. mingw-w64-x86_64-openssl-1.1.1.h-1-any 4.8 MiB 33.8 MiB/s 00:00 [############################################################] 100%
  68. mingw-w64-x86_64-termcap-1.3.1-6-any 28.0 KiB 0.00 B/s 00:00 [############################################################] 100%
  69. mingw-w64-x86_64-readline-8.0.004-1-any 370.5 KiB 0.00 B/s 00:00 [############################################################] 100%
  70. mingw-w64-x86_64-tcl-8.6.10-1-any 3.0 MiB 64.1 MiB/s 00:00 [############################################################] 100%
  71. mingw-w64-x86_64-sqlite3-3.33.0-1-any 7.1 MiB 45.5 MiB/s 00:00 [############################################################] 100%
  72. mingw-w64-x86_64-tk-8.6.10-2-any 1984.4 KiB 121 MiB/s 00:00 [############################################################] 100%
  73. mingw-w64-x86_64-xz-5.2.5-1-any 348.1 KiB 0.00 B/s 00:00 [############################################################] 100%
  74. mingw-w64-x86_64-python-3.8.6-3-any 16.9 MiB 12.6 MiB/s 00:01 [############################################################] 100%
  75. mingw-w64-x86_64-xxhash-0.7.4-1-any 118.3 KiB 0.00 B/s 00:00 [############################################################] 100%
  76. mingw-w64-x86_64-gdb-9.2-3-any 4.0 MiB 7.78 MiB/s 00:01 [############################################################] 100%
  77. mingw-w64-x86_64-libmangle-git-8.0.0.6001.98dad1fe-1-any 23.3 KiB 0.00 B/s 00:00 [############################################################] 100%
  78. mingw-w64-x86_64-make-4.3-1-any 151.6 KiB 9.25 MiB/s 00:00 [############################################################] 100%
  79. mingw-w64-x86_64-pkg-config-0.29.2-2-any 262.7 KiB 8.28 MiB/s 00:00 [############################################################] 100%
  80. mingw-w64-x86_64-tools-git-8.0.0.6001.98dad1fe-1-any 284.6 KiB 8.97 MiB/s 00:00 [############################################################] 100%
  81. mingw-w64-x86_64-winstorecompat-git-8.0.0.6001.98dad1fe-1-any 21.6 KiB 0.00 B/s 00:00 [############################################################] 100%
  82. (45/45) 正在检查密钥环里的密钥 [############################################################] 100%
  83. (45/45) 正在检查软件包完整性 [############################################################] 100%
  84. (45/45) 正在加载软件包文件 [############################################################] 100%
  85. (45/45) 正在检查文件冲突 [############################################################] 100%
  86. (45/45) 正在检查可用存储空间 [############################################################] 100%
  87. :: 正在处理软件包的变化...
  88. ( 1/45) 正在安装 mingw-w64-x86_64-libiconv [############################################################] 100%
  89. ( 2/45) 正在安装 mingw-w64-x86_64-zlib [############################################################] 100%
  90. ( 3/45) 正在安装 mingw-w64-x86_64-binutils [############################################################] 100%
  91. ( 4/45) 正在安装 mingw-w64-x86_64-headers-git [############################################################] 100%
  92. ( 5/45) 正在安装 mingw-w64-x86_64-crt-git [############################################################] 100%
  93. ( 6/45) 正在安装 mingw-w64-x86_64-isl [############################################################] 100%
  94. ( 7/45) 正在安装 mingw-w64-x86_64-gmp [############################################################] 100%
  95. ( 8/45) 正在安装 mingw-w64-x86_64-mpfr [############################################################] 100%
  96. ( 9/45) 正在安装 mingw-w64-x86_64-mpc [############################################################] 100%
  97. (10/45) 正在安装 mingw-w64-x86_64-libwinpthread-git [############################################################] 100%
  98. (11/45) 正在安装 mingw-w64-x86_64-gcc-libs [############################################################] 100%
  99. (12/45) 正在安装 mingw-w64-x86_64-windows-default-manifest [############################################################] 100%
  100. (13/45) 正在安装 mingw-w64-x86_64-winpthreads-git [############################################################] 100%
  101. (14/45) 正在安装 mingw-w64-x86_64-zstd [############################################################] 100%
  102. (15/45) 正在安装 mingw-w64-x86_64-gcc [############################################################] 100%
  103. (16/45) 正在安装 mingw-w64-x86_64-gcc-ada [############################################################] 100%
  104. (17/45) 正在安装 mingw-w64-x86_64-gcc-libgfortran [############################################################] 100%
  105. (18/45) 正在安装 mingw-w64-x86_64-gcc-fortran [############################################################] 100%
  106. (19/45) 正在安装 mingw-w64-x86_64-gcc-objc [############################################################] 100%
  107. (20/45) 正在安装 mingw-w64-x86_64-expat [############################################################] 100%
  108. (21/45) 正在安装 mingw-w64-x86_64-gettext [############################################################] 100%
  109. (22/45) 正在安装 mingw-w64-x86_64-libtre-git [############################################################] 100%
  110. (23/45) 正在安装 mingw-w64-x86_64-libsystre [############################################################] 100%
  111. (24/45) 正在安装 mingw-w64-x86_64-ncurses [############################################################] 100%
  112. (25/45) 正在安装 mingw-w64-x86_64-bzip2 [############################################################] 100%
  113. (26/45) 正在安装 mingw-w64-x86_64-libffi [############################################################] 100%
  114. (27/45) 正在安装 mingw-w64-x86_64-mpdecimal [############################################################] 100%
  115. (28/45) 正在安装 mingw-w64-x86_64-libtasn1 [############################################################] 100%
  116. (29/45) 正在安装 mingw-w64-x86_64-p11-kit [############################################################] 100%
  117. (30/45) 正在安装 mingw-w64-x86_64-ca-certificates [############################################################] 100%
  118. (31/45) 正在安装 mingw-w64-x86_64-openssl [############################################################] 100%
  119. (32/45) 正在安装 mingw-w64-x86_64-termcap [############################################################] 100%
  120. (33/45) 正在安装 mingw-w64-x86_64-readline [############################################################] 100%
  121. (34/45) 正在安装 mingw-w64-x86_64-tcl [############################################################] 100%
  122. (35/45) 正在安装 mingw-w64-x86_64-sqlite3 [############################################################] 100%
  123. (36/45) 正在安装 mingw-w64-x86_64-tk [############################################################] 100%
  124. (37/45) 正在安装 mingw-w64-x86_64-xz [############################################################] 100%
  125. (38/45) 正在安装 mingw-w64-x86_64-python [############################################################] 100%
  126. (39/45) 正在安装 mingw-w64-x86_64-xxhash [############################################################] 100%
  127. (40/45) 正在安装 mingw-w64-x86_64-gdb [############################################################] 100%
  128. (41/45) 正在安装 mingw-w64-x86_64-libmangle-git [############################################################] 100%
  129. (42/45) 正在安装 mingw-w64-x86_64-make [############################################################] 100%
  130. (43/45) 正在安装 mingw-w64-x86_64-pkg-config [############################################################] 100%
  131. (44/45) 正在安装 mingw-w64-x86_64-tools-git [############################################################] 100%
  132. (45/45) 正在安装 mingw-w64-x86_64-winstorecompat-git [############################################################] 100%
  133. Administrator@WinSer-ALYPC MSYS ~

四、通过已绑定MinGW-W64的第三软件进行安装(最省事)

MinGW-W64在Code::Blocks 安装目录D:\Program Files\CodeBlocks\MinGW中,无需配置。

部分软件已**捆绑**MinGW-W64,我们下载安装这样的软件,就相当于安装MinGW-W64。 Code::Blocks 是一个开源、**跨平台、免费的C/C++集成开发环境,该软件已经捆绑**MinGW-W64,你可以通过安装CB来安装MinGW-W64。

详细内容见:
C & C++开发环境介绍