How to install MinGW-w64 With MSYS2

How to install MinGW-w64 With MSYS2

There are many reasons you might want to install MinGW on your system as a developer. For me it was FFmpeg video library. Here's how.

·

3 min read

MinGW-w64 is actually quite popular today because it's a dependency for many other computer programs in wide use, such as FFmpeg (for encoding files in video format.)

I recently had to install MinGW on my Windows PC for just that very purpose! To encode and save videos in different file formats. You may have found this MinGW setup article for a completely different reason and I can totally understand it! Still the MinGW-w64 installation process is similar.

This is probably the best MinGW installation video, if you're someone who learns better from visual instructions, it's probably a good idea to watch this first.

So this is pretty much why I wrote this article, to document the process and hopefully it helps someone going through the same 🙂

Installing MinGW for use with FFMpeg

For those like me, who are installing FFMpeg, here's a more detailed setup process:

  1. Download the latest msys2 installer from msys2.org and run it.
  2. Follow the instructions on the screen to complete the installation.
  3. Start msys2 by double-clicking on the shortcut created in your start menu or desktop.
  4. In the msys2 shell, update the package repositories with the following command:

pacman -Syu

  1. Exit the msys2 shell and restart it.
  2. In the msys2 shell, install mingw w64 with the following command:

pacman -S mingw-w64-i686-toolchain pacman -S mingw-w64-x86_64-toolchain

  1. You can now find the mingw w64 compiler binaries in the /mingw32/bin and /mingw64/bin directories.

  2. In the msys2 shell, install cmake with the following command:

pacman -S cmake

  1. In the msys2 shell, install make with the following command:

pacman -S make

  1. In the msys2 shell, install git with the following command:

pacman -S git

  1. In the msys2 shell, install vim with the following command:

pacman -S vim

  1. You can now find the cmake, make, and git binaries in the /usr/bin directory.
  2. In the msys2 shell, change to the directory where you want the FFmpeg source code to be downloaded. For example:

cd /c/ffmpeg-source

  1. In the msys2 shell, clone the FFmpeg git repository with the following command:

git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg

  1. This will create a directory named ffmpeg in the current directory, which contains the FFmpeg source code.
  2. In the msys2 shell, change to the newly created ffmpeg directory:

cd ffmpeg

  1. Run the following command to configure FFmpeg for building:

./configure --enable-shared --disable-static --disable-debug --disable-doc

  1. Run the following command to build FFmpeg:

make -j4

  1. Run the following command to install FFmpeg:

make install

  1. This will build and install FFmpeg into your msys2 installation directory, which is typically C:\msys64\usr. Notice that we’re not using sudo here, because we installed FFmpeg into our own directory, not into a system directory.
  2. You can check that FFmpeg was installed correctly by running the following command:

ffmpeg -version

You should see output similar to the following:

ffmpeg version 0.10.15-6:0.10.15-1~deb7u1, Copyright (c)

Phew! Finally.

Oh and in some cases you might also want to install MinGW with MSYS2. (because there is a way to install it without MSYS2, but this case is probably a lot more rare for devs.)

Installing MinGW-w64 with MSYS2

You can install the MSYS2 MinGW-w64 compiler toolchain on your system without using MSYS2 by following these instructions:

  1. Download and install the MSYS2 base installer from msys2.org.
  2. Start the MSYS2 MinGW-w64 shell from the start menu.
  3. Run pacman -S mingw-w64-x86_64-toolchain to install the toolchain.
  4. Run pacman -S mingw-w64-x86_64-cmake to install CMake.
  5. Follow the instructions in the README to build your software.
  6. When you're done, close the MSYS2 MinGW-w64 shell.

Installing MinGW-w64 without MSYS2

You can also use the MSYS2 MinGW-w64 compiler toolchain from the command line without using MSYS2 by following these instructions:

  1. Download and install the MSYS2 base installer from msys2.org.
  2. Start the MSYS2 MinGW-w64 shell from the start menu.
  3. Run pacman -S mingw-w64-x86_64-toolchain to install the toolchain.
  4. Follow the instructions in the README to build your software.
  5. When you're done, close the MSYS2 MinGW-w64 shell.