Here’s a short tutorial on how to set up the GNU Compiler Collection (GCC) on Microsoft Windows via MSYS2 (Minimal SYStem 2).
Get MSYS2
Download and install MSYS2:
MSYS2 is a collection of tools and libraries providing you with an easy-to-use environment for building, installing and running native Windows software.
A few notes:
- The installation path should be short and simple (I prefer
C:\MSYS2to the default valueC:\msys64). - What to start after the installation? There are multiple entries listed under “MSYS2” in the start menu!
Go with MSYS2 UCRT64.
Using “Windows Terminal” instead of “MinTTY”
One can prepare a new configuration profile for the Windows Terminal, so that the tools that come with MSYS2 can be called from there (instead of running the separate “MinTTY” program).
But instead of editing the JSON file directly, I do this in the Settings GUI of Windows Terminal:
- Add a new, empty profile
- Name: MSYS2 (UCRT64)
- Command Line:
C:\MSYS2\msys2_shell.cmd -defterm -here -no-start -ucrt64 - Starting Directory:
C:\MSYS2\home\%USERNAME%(just a recommendation) - Icon:
C:\MSYS2\ucrt64.ico
Get GCC (GNU Compiler Collection)
Install the GCC in the form of MinGW-W64 via the MSYS2 package manger “pacman” from a MSYS2 UCRT64 session (see also):
> pacman -S mingw-w64-ucrt-x86_64-gcc
Binaries created with MinGW-W64 will be standalone programs that do not require a cygwin.dll or similar files.
Test: Build from a MSYS2 UCRT64 session
> cd C:/devel/test
> g++ hello.cpp -o C:/devel/test/hello.exe
Note: The starting directory was set to the ‘Home’ directory of the current user (see “Windows Terminal” above),
but if you ‘cd’ up, you can only reach the MSYS2 installation folder (e.g. C:\MSYS2).
Use the forward slash (/) to go elsewhere, not the backslash (\), since MSYS2 is unix-like.
Test: Build from a CMD prompt/Powershell session
> cd C:\MSYS2\ucrt64\bin # Here are some necessary DLLs.
> g++.exe C:/devel/test/hello.cpp -o C:/devel/test/hello.exe
Film & Television (57)
How To (70)
Journal (18)
Miscellaneous (4)
News & Announcements (21)
On Software (12)
Projects (26)