Skip to content

Instantly share code, notes, and snippets.

@Kholdfyre
Forked from lux01/MSYS2 MinGW-W64 Setup.txt
Last active November 7, 2023 23:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kholdfyre/d9f5195e06a58e1a6955929291ff6439 to your computer and use it in GitHub Desktop.
Save Kholdfyre/d9f5195e06a58e1a6955929291ff6439 to your computer and use it in GitHub Desktop.
Simple guide to set-up a MinGW-w64 environment on Windows using MSYS2
Part 1: Installing MSYS2/MinGW-W64
Windows is a piece of shit so to make the projects and code interoperable between Windows and Linux
development environments we need to setup a Linux compatible build environment on Windows.
1. Go to http://msys2.github.io/
2. Follow instructions 1 - 6 on the page. Make sure you remember where you installed this!
NB: For instruction 6 it asks you to close MSYS2, do this by pressing the X button, not
by typing exit (which is how you would normally do it).
3. Type the following command into the MSYS2 shell:
pacman -Sy base-devel mingw-w64-x86_64-gcc mingw-w64-x86_64-glew mingw-w64-x86_64-SDL2
This will install basic development tools (base-devel), the GCC C(++) compiler for Windows,
the GLEW library (http://glew.sourceforge.net/) which is a library that makes working with
OpenGL simple, and SDL2 (http://www.libsdl.org/) which is a cross-platform development
library providing easy access to audio, keyboard, mouse, and graphics hardware.
Part 2: Installing an IDE
I personally use the Code::Blocks IDE for C(++) development. It's an open-source program with pre-
build Windows binaries. They ship two versions of the IDE for Windows, one with a C compiler and one
without. We will be using the one without a C compiler as the one they ship is for 32-bit programs.
1. Go to http://www.codeblocks.org/downloads/26
2. Download the file codeblocks-13.12-setup.exe using the Sourceforge.net link
3. Run the installer and launch Code::Blocks.
Since we're using our own installation of the C compiler we need to poke Code::Blocks in the right
direction so it knows what to run.
4. Go to Settings->Compiler.
5. If the selected compiler is not "GNU GCC Compiler", select it and set it as default
6. Go to the Toolchain executables tab.
7. Set the compiler's install directory. If you didn't change the install directory earlier then
you will need to set it to
C:\msys64\mingw64
otherwise you'll need to change it to your install directory, and add on mingw64 to the end.
8. Change the program files to the following:
C compiler: gcc.exe
C++ compiler: g++.exe
Linker for dynamic libs: g++.exe
Linker for static libs: ar.exe
Resource compiler: windres.exe
Make program: mingw32-make.exe
If the debugger says "Invalid debugger" then you will need to come back here after the next
section to set up the debugger.
As a final step we need to configure a debugger so we can inspect our programs as they run and
diagnose problems. We'll be using GDB which is a good debugger but a bit hard to use if you're not
used to it. The Visual Studio debugger is great but we'd need to run two separate projects to be
able to use the VS debugger easily, which is a lot of hassle.
9. Go to Settings->Debugger.
10. Go to GDB/CDB debugger. If a profile already exists, go to it. Otherwise create a new configure
with a name of your choice.
11. Set the executable path to
C:\msys64\usr\bin\gdb.exe
You will need to change the first part if you changed the install location for MSYS2 at the
start of this guide.
12. Set the debugger type to GDB. Enable the following options:
Watch function arguments
Watch local variables
Enable watch scripts
Catch C++ exceptions
I leave the rest disabled but you could turn them on if you want.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment