MSYS2的安装与使用及MinGW64安装配置
MSYS2是工具和库的集合,为您提供了一个易于使用的环境,用于构建,安装和运行本机Windows软件。
它由一个名为mintty的命令行终端 ,bash,git和subversion之类的版本控制系统,tar和awk之类的工具,甚至是autotools之类的构建系统,全部基于Cygwin的修改版。尽管其中一些中心部分基于Cygwin,但MSYS2的主要重点是为本机Windows软件提供构建环境,并使使用Cygwin的部分最少。MSYS2为GCC,mingw-w64,CPython,CMake,Meson,OpenSSL,FFmpeg,Rust,Ruby等提供了最新的本机版本。
为了提供易于安装的软件包并保持更新状态,它具有一个名为Pacman的软件包管理系统,Arch Linux用户应该熟悉该系统 。它带来了许多强大的功能,例如依赖性解析和简单的完整系统升级,以及直接且可复制的程序包构建。我们的软件包存储库包含2000多个预安装的软件包,可供安装。
一、安装:
1、下载MSYS2的exe包,下载地址:https://repo.msys2.org/distrib/x86_64/
2、双击安装包,选择安装目录,即可。
注:安装完成后,点击“完成”后,显示控制台窗口反应速度有些慢,耐心等待。
二、更新软件包数据库和基本软件包
注:此处下载包时,可能会有下载失败或超时等情况,这是由于网络原因造成的,那么解决办法就是在命令执行完成后,再次执行命令,直到成功为止。[expected download size exceeded]
1、从“开始”菜单运行“ MSYS2 MSYS”。
2、如果安装的不是最新的MSYS2,则使用下面命令更新。如果是最新的,则跳过此步骤,进入下一步骤。最后会有报错,官网说这是预期的,不会影响使用。
| 0 | $ pacman -Syu | 
3、更新其余的基本软件包,我在这里安装软件时会有一些报错。
| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | $ pacman -Su :: Starting core system upgrade...  there is nothing to do :: Starting full system upgrade... resolving dependencies... looking for conflicting packages... Packages (33) base-2020.12-1  bsdtar-3.5.1-1  curl-7.74.0-4  dash-0.5.11.3-1  gdbm-1.19-1  glib2-2.66.4-2  gmp-6.2.1-1  gnupg-2.2.27-1  icu-68.2-1               libassuan-2.5.4-1  libcurl-7.74.0-4  libedit-20191231_3.1-2  libgdbm-1.19-1  libgnutls-3.7.0-1  libgpg-error-1.41-2  libgpgme-1.15.1-1               libhogweed-3.7-1  liblz4-1.9.3-1  libnettle-3.7-1  libopenssl-1.1.1.i-1  libp11-kit-0.23.22-2  libpcre2_8-10.36-1  libreadline-8.1.0-1               libsqlite-3.34.0-1  libxml2-2.9.10-7  libzstd-1.4.8-1  nano-5.4-1  nettle-3.7-1  openssl-1.1.1.i-1  p11-kit-0.23.22-2  tzcode-2020f-1  wget-1.21.1-2               zstd-1.4.8-1 Total Download Size:   25.06 MiB Total Installed Size:  86.34 MiB Net Upgrade Size:       4.23 MiB :: Proceed with installation? [Y/n] y :: Retrieving packages...  liblz4-1.9.3-1-x86_64                                                  82.5 KiB  35.8 KiB/s 00:02  100%  gmp-6.2.1-1-x86_64                                                    384.8 KiB  43.1 KiB/s 00:09  100%  libhogweed-3.7-1-x86_64                                               183.4 KiB  35.1 KiB/s 00:05  100%  libnettle-3.7-1-x86_64                                                129.3 KiB  38.7 KiB/s 00:03  100%  icu-68.2-1-x86_64                                                       9.4 MiB  62.8 KiB/s 02:34  100%  libreadline-8.1.0-1-x86_64                                            288.1 KiB  71.1 KiB/s 00:04  100%  libxml2-2.9.10-7-x86_64                                               540.8 KiB  99.8 KiB/s 00:05  100%  libzstd-1.4.8-1-x86_64                                                276.1 KiB  53.6 KiB/s 00:05  100%  bsdtar-3.5.1-1-x86_64                                                1098.2 KiB  44.9 KiB/s 00:24  100%  libopenssl-1.1.1.i-1-x86_64                                          1222.1 KiB  66.5 KiB/s 00:18  100% error: failed retrieving file 'openssl-1.1.1.i-1-x86_64.pkg.tar.zst' from downloads.sourceforge.net : Operation timed out after 10001 milliseconds with 0 out of 0 bytes received  openssl-1.1.1.i-1-x86_64                                              594.4 KiB   278 KiB/s 00:02  100%  libgpg-error-1.41-2-x86_64                                            173.6 KiB  58.0 KiB/s 00:03  100%  glib2-2.66.4-2-x86_64                                                   2.3 MiB  48.3 KiB/s 00:48  100%  libp11-kit-0.23.22-2-x86_64                                           193.4 KiB   126 KiB/s 00:02  100% error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from downloads.sourceforge.net : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from www2.futureware.at : expected download size exceeded###########--------------------]  65% error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from mirror.yandex.ru : expected download size exceeded error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from mirrors.tuna.tsinghua.edu.cn : expected download size exceeded error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from mirrors.ustc.edu.cn : expected download size exceeded error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from mirror.bit.edu.cn : expected download size exceeded error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from mirror.selfnet.de : expected download size exceeded error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from mirrors.sjtug.sjtu.edu.cn : expected download size exceeded error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from mirror.jmu.edu : expected download size exceeded error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from ftp.cc.uoc.gr : expected download size exceeded error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from ftp.acc.umu.se : expected download size exceeded error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from mirrors.piconets.webwerks.in : expected download size exceeded error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from quantum-mirror.hu : expected download size exceeded error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from mirrors.dotsrc.org : expected download size exceeded error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from mirror.ufro.cl : expected download size exceeded error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from mirror.clarkson.edu : expected download size exceeded error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from ftp.nluug.nl : expected download size exceeded error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from download.nus.edu.sg : expected download size exceeded error: failed retrieving file 'p11-kit-0.23.22-2-x86_64.pkg.tar.zst' from ftp.osuosl.org : expected download size exceeded warning: failed to retrieve some files  libsqlite-3.34.0-1-x86_64                                             604.8 KiB  24.9 KiB/s 00:24  100%  libedit-20191231_3.1-2-x86_64                                          96.2 KiB  16.4 KiB/s 00:06  100%  libcurl-7.74.0-4-x86_64                                               243.6 KiB  39.6 KiB/s 00:06  100%  curl-7.74.0-4-x86_64                                                  810.5 KiB  25.8 KiB/s 00:31  100%  dash-0.5.11.3-1-x86_64                                                 77.4 KiB  95.8 KiB/s 00:01  100%  nano-5.4-1-x86_64                                                     579.6 KiB  30.7 KiB/s 00:19  100%  tzcode-2020f-1-x86_64                                                 238.2 KiB  24.7 KiB/s 00:10  100% error: failed retrieving file 'libassuan-2.5.4-1-x86_64.pkg.tar.zst' from downloads.sourceforge.net : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds  libassuan-2.5.4-1-x86_64                                               89.8 KiB  96.0 KiB/s 00:01  100% error: failed retrieving file 'libgnutls-3.7.0-1-x86_64.pkg.tar.zst' from downloads.sourceforge.net : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds  libgnutls-3.7.0-1-x86_64                                             1375.7 KiB   150 KiB/s 00:09  100% error: failed retrieving file 'nettle-3.7-1-x86_64.pkg.tar.zst' from downloads.sourceforge.net : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds  nettle-3.7-1-x86_64                                                    92.5 KiB   163 KiB/s 00:01  100% error: failed retrieving file 'gnupg-2.2.27-1-x86_64.pkg.tar.zst' from downloads.sourceforge.net : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds  gnupg-2.2.27-1-x86_64                                                   2.2 MiB   682 KiB/s 00:03  100% error: failed retrieving file 'libgpgme-1.15.1-1-x86_64.pkg.tar.zst' from downloads.sourceforge.net : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds  libgpgme-1.15.1-1-x86_64                                              351.8 KiB  71.9 KiB/s 00:05  100% error: failed retrieving file 'libpcre2_8-10.36-1-x86_64.pkg.tar.zst' from downloads.sourceforge.net : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds  libpcre2_8-10.36-1-x86_64                                             119.7 KiB  10.6 KiB/s 00:11  100% error: failed retrieving file 'wget-1.21.1-2-x86_64.pkg.tar.zst' from downloads.sourceforge.net : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds  wget-1.21.1-2-x86_64                                                  752.3 KiB  65.8 KiB/s 00:11  100% error: failed retrieving file 'zstd-1.4.8-1-x86_64.pkg.tar.zst' from downloads.sourceforge.net : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds  zstd-1.4.8-1-x86_64                                                   332.2 KiB  67.4 KiB/s 00:05  100% error: failed retrieving file 'libgdbm-1.19-1-x86_64.pkg.tar.zst' from downloads.sourceforge.net : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds  libgdbm-1.19-1-x86_64                                                  28.9 KiB  36.5 KiB/s 00:01  100% error: failed retrieving file 'gdbm-1.19-1-x86_64.pkg.tar.zst' from downloads.sourceforge.net : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds  gdbm-1.19-1-x86_64                                                    146.5 KiB  45.0 KiB/s 00:03  100% error: failed retrieving file 'base-2020.12-1-any.pkg.tar.zst' from downloads.sourceforge.net : Operation too slow. Less than 1 bytes/sec transferred the last 10 seconds  base-2020.12-1-any                                                      3.3 KiB  3.19 MiB/s 00:00  100% error: failed to commit transaction (unexpected error) Errors occurred, no packages were upgraded. | 
上面有报错,继续,直到出现下面提示为止:
| 0 1 2 3 4 | $ pacman -Su :: Starting core system upgrade...  there is nothing to do :: Starting full system upgrade...  there is nothing to do | 
4、现在,MSYS2已为您准备就绪。您可能需要安装一些工具和mingw-w64 GCC才能开始编译。在使用如下命令时遇到询问,按回车即可。
| 0 | $ pacman -S --needed base-devel mingw-w64-x86_64-toolchain | 
如果要安装mingw32位环境的,应该使用如下命令(没测试):
| 0 | $ pacman -S --needed base-devel mingw-w64-i686-toolchain | 
没有报错,为了验证,我又跑了一遍命令。
| 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | $ pacman -S --needed base-devel mingw-w64-x86_64-toolchain warning: asciidoc-9.0.4-1 is up to date -- skipping warning: autoconf-2.69-5 is up to date -- skipping warning: autoconf2.13-2.13-3 is up to date -- skipping warning: autogen-5.18.16-1 is up to date -- skipping warning: automake-wrapper-11-1 is up to date -- skipping warning: automake1.10-1.10.3-4 is up to date -- skipping warning: automake1.11-1.11.6-4 is up to date -- skipping warning: automake1.12-1.12.6-4 is up to date -- skipping warning: automake1.13-1.13.4-5 is up to date -- skipping warning: automake1.14-1.14.1-4 is up to date -- skipping warning: automake1.15-1.15.1-2 is up to date -- skipping warning: automake1.16-1.16.2-2 is up to date -- skipping warning: automake1.6-1.6.3-3 is up to date -- skipping warning: automake1.7-1.7.9-3 is up to date -- skipping warning: automake1.8-1.8.5-4 is up to date -- skipping warning: automake1.9-1.9.6-3 is up to date -- skipping warning: bison-3.7.4-1 is up to date -- skipping warning: btyacc-20200910-1 is up to date -- skipping warning: diffstat-1.63-1 is up to date -- skipping warning: diffutils-3.7-1 is up to date -- skipping warning: dos2unix-7.4.2-1 is up to date -- skipping warning: file-5.39-2 is up to date -- skipping warning: flex-2.6.4-1 is up to date -- skipping warning: gawk-5.1.0-1 is up to date -- skipping warning: gdb-9.2-3 is up to date -- skipping warning: gettext-0.19.8.1-1 is up to date -- skipping warning: gettext-devel-0.19.8.1-1 is up to date -- skipping warning: gperf-3.1-2 is up to date -- skipping warning: grep-3.0-2 is up to date -- skipping warning: groff-1.22.4-1 is up to date -- skipping warning: help2man-1.47.16-1 is up to date -- skipping warning: intltool-0.51.0-2 is up to date -- skipping warning: libtool-2.4.6-9 is up to date -- skipping warning: libunrar-6.0.3-1 is up to date -- skipping warning: libunrar-devel-6.0.3-1 is up to date -- skipping warning: m4-1.4.18-2 is up to date -- skipping warning: make-4.3-1 is up to date -- skipping warning: man-db-2.9.3-1 is up to date -- skipping warning: pacman-5.2.2-9 is up to date -- skipping warning: pactoys-git-r2.07ca37f-1 is up to date -- skipping warning: patch-2.7.6-1 is up to date -- skipping warning: patchutils-0.4.2-1 is up to date -- skipping warning: perl-5.32.0-2 is up to date -- skipping warning: pkgconf-1.7.3-2 is up to date -- skipping warning: pkgfile-21-1 is up to date -- skipping warning: quilt-0.66-2 is up to date -- skipping warning: reflex-20200715-1 is up to date -- skipping warning: scons-3.1.2-4 is up to date -- skipping warning: sed-4.8-1 is up to date -- skipping warning: swig-4.0.2-1 is up to date -- skipping warning: texinfo-6.7-3 is up to date -- skipping warning: texinfo-tex-6.7-3 is up to date -- skipping warning: ttyrec-1.0.8-2 is up to date -- skipping warning: unrar-6.0.3-1 is up to date -- skipping warning: wget-1.21.1-2 is up to date -- skipping warning: xmlto-0.0.28-2 is up to date -- skipping warning: mingw-w64-x86_64-binutils-2.35.1-3 is up to date -- skipping warning: mingw-w64-x86_64-crt-git-9.0.0.6090.ad98746a-1 is up to date -- skipping warning: mingw-w64-x86_64-gcc-10.2.0-6 is up to date -- skipping warning: mingw-w64-x86_64-gcc-ada-10.2.0-6 is up to date -- skipping warning: mingw-w64-x86_64-gcc-fortran-10.2.0-6 is up to date -- skipping warning: mingw-w64-x86_64-gcc-libgfortran-10.2.0-6 is up to date -- skipping warning: mingw-w64-x86_64-gcc-libs-10.2.0-6 is up to date -- skipping warning: mingw-w64-x86_64-gcc-objc-10.2.0-6 is up to date -- skipping warning: mingw-w64-x86_64-gdb-10.1-2 is up to date -- skipping warning: mingw-w64-x86_64-gdb-multiarch-10.1-2 is up to date -- skipping warning: mingw-w64-x86_64-headers-git-9.0.0.6090.ad98746a-1 is up to date -- skipping warning: mingw-w64-x86_64-libgccjit-10.2.0-6 is up to date -- skipping warning: mingw-w64-x86_64-libmangle-git-9.0.0.6090.ad98746a-1 is up to date -- skipping warning: mingw-w64-x86_64-libwinpthread-git-9.0.0.6090.ad98746a-1 is up to date -- skipping warning: mingw-w64-x86_64-make-4.3-1 is up to date -- skipping warning: mingw-w64-x86_64-pkgconf-1.7.3-5 is up to date -- skipping warning: mingw-w64-x86_64-tools-git-9.0.0.6090.ad98746a-1 is up to date -- skipping warning: mingw-w64-x86_64-winpthreads-git-9.0.0.6090.ad98746a-1 is up to date -- skipping warning: mingw-w64-x86_64-winstorecompat-git-9.0.0.6090.ad98746a-1 is up to date -- skipping  there is nothing to do | 
5、关闭MSYS2 MSYS窗口
三、MSYS2的使用
要使用mingw-w64 GCC开始构建,需要从“开始”菜单运行【MSYS MinGW 64-bit】。现在,就可以使用make或gcc构建Windows的软件。
MSYS2文档 https://www.msys2.org/wiki/MSYS2-introduction/