Setting Up Msys2;MinGW64 for Windows

Guide to creating windows build environment for MinGW64


Many of us Windows users try to have Visual Studio environment.
But that’s not always great option. Unless you are ready to download 8GB on your internet bandwidth.

I personally like Visual Studio and its fast upcoming cousin VS Code. But hate the large download part.

Hence an opensource alternative is a need of the hour.
Also if you like to compile linuxy style code with Makefile in all its glory.

MinGW64 at your service friend!

Well installing MinGW64 bare can be daunting task. However it comes in a package deal with a friendly Msys2 Environment. Now start with this.

Msys2 Install in Windows

#1 Download Msys2

Downloading the correct version of the Msys2 is essential.

Links:

#2 Installation

Typical installation process starts when run the downloaded install file.
Make sure to keep the C:\msys64 or C:\msys32 intact (based on your architecture).

This is important in case you have the older version of MinGW.
Typically this would be in the C:\MinGW folder.
As observed in ESP8266 Unofficial Windows Development Environment post.

There are some pictures in the Msys2 Website. You can follow them as well. They give you the steps that we are going to talk about next.

#3 Updating Msys2 Installation

Well one might wonder, I just installed a fresh copy. Why on earth do I need to update.

Friend, it helps to be updated. Code contributions never stop in the open-source world.

Ya, even though you got the updated latest copy but you still need to run this.

Double click on the 64-bit Environment icon

Msys2 64bit Environment Icon

You should get something like

Note : In my case I have edited the default font since I can’t see small font stuff. Its explained later.

Msys2 64bit Window

Many of you might not get the bold fonts that are shown above. So here are the setting for all those like myself with poor eyesight.

Note : Use the Window menu on the Top Left cornet menu click on Options...

Msys2 64bit Window Options

Msys2 64bit Window Text

At the Prompt Issue the command:

$ pacman -Syu

:: Synchronizing package databases...
 mingw32                      437.2 KiB   278K/s 00:02 [###########################] 100%
 mingw32.sig                  119.0   B   116K/s 00:00 [###########################] 100%
 mingw64                      438.2 KiB   418K/s 00:01 [###########################] 100%
 mingw64.sig                  119.0   B   116K/s 00:00 [###########################] 100%
 msys                         171.5 KiB   640K/s 00:00 [###########################] 100%
 msys.sig                     119.0   B  0.00B/s 00:00 [###########################] 100%
:: Starting core system upgrade...
warning: terminate other MSYS2 programs before proceeding
resolving dependencies...
looking for conflicting packages...

Packages (2) filesystem-2018.08-1  mintty-1~2.9.0-1

Total Download Size:   0.31 MiB
Total Installed Size:  0.93 MiB
Net Upgrade Size:      0.05 MiB

:: Proceed with installation? [Y/n]

It should sync Database and Download the needed packages.

Note : This command updates the Msys2 itself !

Just say Y or y to begin the install.

Next it should show something like


:: Proceed with installation? [Y/n] y
:: Retrieving packages...
 filesystem-2018.08-1-x86_64   43.7 KiB  10.7M/s 00:00 [###########################] 100%
 mintty-1~2.9.0-1-x86_64      275.6 KiB   347K/s 00:01 [###########################] 100%
(2/2) checking keys in keyring                         [###########################] 100%
(2/2) checking package integrity                       [###########################] 100%
(2/2) loading package files                            [###########################] 100%
(2/2) checking for file conflicts                      [###########################] 100%
(2/2) checking available disk space                    [###########################] 100%
:: Processing package changes...
(1/2) upgrading filesystem                             [###########################] 100%
(2/2) upgrading mintty                                 [###########################] 100%
warning: terminate MSYS2 without returning to shell and check for updates again
warning: for example close your terminal window instead of calling exit

Don’t worry WARNING just do as it says terminate the window, by clicking the Close button on Top right.

Just click Ok

Msys2 64bit Window Close Warning

#4 Updating Packages installed by Msys2

Open the Msys2 64-bit Environment again.

Give the commands:


$ pacman -Su
:: Starting core system upgrade...
 there is nothing to do
:: Starting full system upgrade...
resolving dependencies...
looking for conflicting packages...

Packages (10) curl-7.61.0-2  info-6.5-1  libcurl-7.61.0-2  libnpth-1.6-1
              mingw-w64-x86_64-crt-git-6.0.0.5193.a081b583-1
              mingw-w64-x86_64-gcc-8.2.0-1  mingw-w64-x86_64-gcc-libs-8.2.0-1
              mingw-w64-x86_64-headers-git-6.0.0.5193.a081b583-1  sed-4.5-1
              ttyrec-1.0.8-2

Total Download Size:    38.71 MiB
Total Installed Size:  266.18 MiB
Net Upgrade Size:        7.57 MiB

:: Proceed with installation? [Y/n]

Note : This command updates the packages in the Msys2 like gcc, curl .etc.

Just say Y or y to begin the install.

Next it should show something like

:: Proceed with installation? [Y/n] y
:: Retrieving packages...
 mingw-w64-x86_64-he...     5.1 MiB   663K/s 00:08 [#####################] 100%
 mingw-w64-x86_64-cr...     2.9 MiB  1485K/s 00:02 [#####################] 100%
 mingw-w64-x86_64-gc...   564.7 KiB  2.10M/s 00:00 [#####################] 100%
 mingw-w64-x86_64-gc...    28.7 MiB  3.37M/s 00:09 [#####################] 100%
 sed-4.5-1-x86_64         223.2 KiB  10.4M/s 00:00 [#####################] 100%
 info-6.5-1-x86_64        182.5 KiB  10.5M/s 00:00 [#####################] 100%
 libcurl-7.61.0-2-x86_64  228.7 KiB  11.2M/s 00:00 [#####################] 100%
 curl-7.61.0-2-x86_64     764.8 KiB  9.45M/s 00:00 [#####################] 100%
 libnpth-1.6-1-x86_64      21.8 KiB  7.11M/s 00:00 [#####################] 100%
 ttyrec-1.0.8-2-x86_64     25.9 KiB  8.45M/s 00:00 [#####################] 100%
(10/10) checking keys in keyring                   [#####################] 100%
(10/10) checking package integrity                 [#####################] 100%
(10/10) loading package files                      [#####################] 100%
(10/10) checking for file conflicts                [#####################] 100%
(10/10) checking available disk space              [#####################] 100%
:: Processing package changes...
( 1/10) upgrading sed                              [#####################] 100%
( 2/10) upgrading info                             [#####################] 100%
( 3/10) upgrading libcurl                          [#####################] 100%
( 4/10) upgrading curl                             [#####################] 100%
( 5/10) upgrading libnpth                          [#####################] 100%
( 6/10) upgrading mingw-w64-x86_64-headers-git     [#####################] 100%
( 7/10) upgrading mingw-w64-x86_64-crt-git         [#####################] 100%
( 8/10) upgrading mingw-w64-x86_64-gcc-libs        [#####################] 100%
( 9/10) upgrading mingw-w64-x86_64-gcc             [#####################] 100%
(10/10) upgrading ttyrec                           [#####################] 100%

That’s it we are ready to install our favorite MinGW64 Environment now.

#5 Installing MinGW64 Environment

$ pacman -Sy nano gcc wget autoconf automake make git

And Y or y to begin the install.

This command install the Bear Necessities for MinGW64 Compilation Environment

To test out our installed tools:

$ gcc -v

Using built-in specs.
COLLECT_GCC=C:\msys64\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-8.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/x86_64-w64-mingw32/include --libexecdir=/mingw64/lib --enable-bootstrap --with-arch=x86-64 --with-tune=generic --enable-languages=ada,c,lto,c++,objc,obj-c++,fortran --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts=yes --enable-libstdcxx-time=yes --disable-libstdcxx-pch --disable-libstdcxx-debug --disable-isl-version-check --enable-lto --enable-libgomp --disable-multilib --enable-checking=release --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev1, Built by MSYS2 project' --with-bugurl=https://sourceforge.net/projects/msys2 --with-gnu-as --with-gnu-ld
Thread model: posix
gcc version 8.2.0 (Rev1, Built by MSYS2 project)

$ make -v
GNU Make 4.2.1
Built for x86_64-pc-msys
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Congratulations !!

You are now ready to do all that Makefile stuff and compilation on Windows!

Trivia

You might have noticed the interesting ; semicolon in the name.
Its a tribute to Steins;Gate and my favorite Mad Scientist - Hououin Kyouma.
For the inspiration to think different and be righteous - from सकर्म ==> अकर्म.
Watch it if you ever get time.

 
comments powered by Disqus