如何安装 MinGW-w64和 MSYS2?

我正在尝试构建一些开源库。我需要软件包管理系统来轻松下载依赖项。起初我使用的是 MinGW+MSYS。但是包含的套餐是有限的。有人叫我用 MinGW-w64 + MSYS2

我从 给你下载了 mingw-w64-install。当运行时,它报告以下错误。如何修复它?

enter image description here

顺便说一下,从 MinGW-w64的下载页面,我看到了很多下载链接。甚至 Cygwin 也在名单上。CygwinMinGW-w64是如何相互关联的?

enter image description here

我目前的理解是,在 MinGW+MSYS时代,MSYS 只是 MinGW 的一个不错的插件,而在 MinGW-w64 + MSYS2时代,MSYS2是独立的,MinGW-w64只是一组可以使用的库。就像 Cygwin 可以下载很多不同的软件包一样。

165828 次浏览

Unfortunately, the MinGW-w64 installer you used sometimes has this issue. I myself am not sure about why this happens (I think it has something to do with Sourceforge URL redirection or whatever that the installer currently can't handle properly enough).

Anyways, if you're already planning on using MSYS2, there's no need for that installer.

  1. Download MSYS2 from this page.

  2. After the install completes, click on the newly created "MSYS2 Shell" option under either MSYS2 64-bit or MSYS2 32-bit in the Start menu (or mingw64.exe or mingw32.exe in the installation directory).

    If done correctly, the terminal prompt will say MINGW64 or MINGW32 respectively, not MSYS.

  3. Update MSYS2 using pacman -Syuu. If it closes itself during the update, restart it and repeat the same command to finish the update.

    You should routinely update your installation.

  4. Install a toolchain

    a) for 64-bit:

    pacman -S mingw-w64-x86_64-toolchain
    

    b) for 32-bit:

    pacman -S mingw-w64-i686-toolchain
    

    This includes GCC (the compiler), GDB (the debugger), and more.

  5. Install any libraries/tools you may need. You can search the repositories by doing

    pacman -Ss name_of_something_i_want_to_install
    

    e.g.

    pacman -Ss gsl
    

    and install using

    pacman -S package_name_of_something_i_want_to_install
    

    e.g.

    pacman -S mingw-w64-x86_64-gsl
    

    and from then on the GSL library will be automatically found by your compiler!

    Make sure any compilers and libraries you install have this package prefix (mingw-w64-x86_64- for 64-bit or mingw-w64-i686- for 32-bit). Only use unprefixed packages for misc command-line utilities (such as grep, sed, make, etc), unless you know what you're doing.

  6. Verify that the compiler is working by doing

    gcc --version
    

If you want to use the toolchains (with installed libraries) outside of the MSYS2 environment, all you need to do is add <MSYS2 root>/mingw64/bin or <MSYS2 root>/mingw32/bin to your PATH.

MSYS has not been updated a long time, MSYS2 is more active, you can download from MSYS2, it has both mingw and cygwin fork package.

To install the MinGW-w64 toolchain (Reference):

  1. Open MSYS2 shell from start menu
  2. Run pacman -Sy pacman to update the package database
  3. Re-open the shell, run pacman -Syu to update the package database and core system packages
  4. Re-open the shell, run pacman -Su to update the rest
  5. Install compiler:
    • For 32-bit target, run pacman -S mingw-w64-i686-toolchain
    • For 64-bit target, run pacman -S mingw-w64-x86_64-toolchain
  6. Select which package to install, default is all
  7. You may also need make, run pacman -S make

You can now also get the standalone personal build of MinGW-w64 from https://winlibs.com/ which requires no installation - just extract and its ready to use. This allow having multiple toolchains on the same system (e.g. one for Windows 32-bit and another for Windows 64-bit).