100

I am trying to build some open source library. I need package management system to easily download the dependencies. At first I am using MinGW+MSYS. But the included packages are limited. Someone told me to use MinGW-w64 + MSYS2.

I downloaded the mingw-w64-install from here. When running, it reports the following error. How to fix it?

enter image description here

And btw, from the MinGW-w64 download page, I see a lot of download links. Even Cygwin is listed. How Cygwin and MinGW-w64 are related?

enter image description here

My current understanding is, in the time of MinGW+MSYS, MSYS is just a nice addon to MinGW, while in MinGW-w64 + MSYS2, MSYS2 is standalone and MinGW-w64 is just a set of libraries it can work with. Just like Cygwin can download many different packges.

smwikipedia
  • 57,565
  • 86
  • 288
  • 461

3 Answers3

231

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.

HolyBlackCat
  • 63,700
  • 7
  • 105
  • 170
rubenvb
  • 72,003
  • 32
  • 177
  • 319
  • 4
    Thanks. How can I get the canonical name of a package that `pacman` can recognize? – smwikipedia May 06 '15 at 12:30
  • 1
    Will it work if you install both 32 and 64 bit toolchains simultaneously? – Colonel Panic Sep 28 '15 at 18:00
  • 2
    @Colonel yes, it will install the toolchains (and any 3rd party libraries you install) in separate directories (/mingw32 and /mingw64). – rubenvb Sep 29 '15 at 06:23
  • 1
    To use in MSYS2 shell I had to do: PATH=/mingw64/bin:$PATH – Nick Westgate Mar 30 '16 at 22:55
  • 6
    Thank you so much @rubenvb. The msys2 wiki is so confusing to noobs like myself on how to do these few simple steps. – Toby May 06 '16 at 12:39
  • 1
    @Toby I agree they take "the Arch Way" in explaining things, i.e. read the Arch wiki on pacman and you'd know nearly the same. A beginner's setup might be useful, although it is now on SO which should turn up on Google quite quickly :). (read this as: keep upvoting this answer :P) – rubenvb May 06 '16 at 12:49
  • 1
    Reading the pacman documentation took me about half an hour to figure out how to actually install things instead of just listing them, LOL - Much more used to yum or apt-get! – Toby May 06 '16 at 14:19
  • @Toby you need to work on your reading skills: https://wiki.archlinux.org/index.php/Pacman#Installing_specific_packages. – rubenvb May 06 '16 at 14:23
  • @rubenvb Ah that is indeed easier! I was looking at https://www.archlinux.org/pacman/pacman.8.html – Toby May 06 '16 at 14:35
  • 2
    Using `pacman` to install `mingw-w64` is a great advice. I faced the same issue while trying to install mingw-w64 behing a proxy. Installing MSYS2 first, setting environment variables for the proxy like http://superuser.com/questions/713582/mingw-installer-not-working-with-proxy and following your answer works perfectly. – francis Aug 19 '16 at 11:22
  • Thanks so much for this post - this should seriously replace the [windows compilation guides](https://trac.ffmpeg.org/wiki/CompilationGuide#Windows). Is there anything you can add to this about cross compiling? When using MSYS2 and following the guide, there are issues with using the --cross-prefix=i686-w64-mingw32-. Perhaps this is unnecessary with how MSYS2 installs the gcc and instead relies on the order of environment variables specified in PATH? – ajbeaven Mar 12 '17 at 04:45
  • In case you need cmake, you have to install `pacman -S mingw-w64-x86_64-cmake` and *NOT* `cmake`. Normal cmake will lack generators for minGW. – user136036 Jan 15 '20 at 19:59
  • Regarding step 5. (Open a MinGW-w64 shell): When the tools are installed using the Chocolatey packet manager the shell must be opened manually from the directory `C:\tools\msys64` – k_o_ May 26 '20 at 23:26
  • Beware that this instruction is not enough to get `std::thread` and `std::mutex` working in MinGW. See [here](https://stackoverflow.com/questions/63582175/why-doesnt-my-compiler-recognize-include-thread-c) for more info. – rustyx Oct 27 '20 at 23:33
  • Is it okay if I install mingW-w64 **SEPARATELY** using mingw-w64 install file, and then install MSYS2 through its x86_64 installer? –  Nov 13 '20 at 17:01
  • @Valsak yes, that's possible (the MSYS2 MinGW-w64 x86_64 GCC is a native compiler toolchain like any other). Just don't install the separate MinGW-w64 install inside the MSYS2 tree ir you'll mess up MSYS2's file tracking. By installing a separate toolchain, you can more easily stick to a specific GCC version, but you lose the convenience of having everyting updating as a whole. – rubenvb Nov 15 '20 at 09:47
49

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
M.M
  • 134,614
  • 21
  • 188
  • 335
Steely Wing
  • 14,459
  • 6
  • 54
  • 51
  • 3
    how do i install specific MinGW-w64 version like `x86_64-6.2.0-release-posix-seh-rt_v5-rev1`? – Youda008 Dec 08 '16 at 14:12
  • 1
    Does that mean the mingw installer as described [here](http://www.mingw.org/wiki/Getting_Started) is not necessary anymore? and I should just install msys2? – lanoxx Feb 17 '17 at 10:45
  • 1
    Link `Reference` is broken – Jean-Francois T. Sep 11 '17 at 06:59
  • any ideas on why msys2 shell would close itself after a second? – A_P May 09 '19 at 22:36
  • 2
    In case you need cmake, you have to install `pacman -S mingw-w64-x86_64-cmake` and *NOT* `cmake`. Normal cmake will lack generators for minGW. – user136036 Jan 15 '20 at 19:57
  • Important note -- when using the pacman upgrade commands, it may show a message telling you to force close the window -- it's important to actually obey the message – M.M Mar 09 '20 at 01:39
0

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).

Brecht Sanders
  • 4,723
  • 1
  • 11
  • 29
  • MSYS2 also supports multiple toolchains per installation (and multiple installations). Winlibs is indeed easy to use, but lacks a package manager (i.e. no prebuilt libraries) and a linux-like environment (can't build stuff using Autotools). – HolyBlackCat Nov 23 '21 at 19:07
  • 1
    @HolyBlackCat Thanks for your insights. I'm actually working on a package manager for winlibs, and I'm making it cross-platform. – Brecht Sanders Nov 23 '21 at 22:15