HOME About NCOT Documentation Social Media Mastodon Support Me

Drink tea and make things

Blog Electronics Labs ZX Spectrum Next Computer Science Z80 Homebrew Computer Arduino and Microcontrollers

Setting up MSYS2 and LibSDL2 for graphics programming in Windows

Posted:

I’m starting a graphics based project, and decided to use SDL2 in Windows. This meant setting up a development environment. Here’s some notes on how I set up MSYS2, VS Code and LibSDL2.

Installing MSYS2

The first step is to install MSYS2 which is a sort of POSIX-y build environment for Windows. They do a better explanation. It’s Cygwin but not shit is my explanation.

They have an installer, you install it.

Then the build tools need installing, they give an example of how to do this

pacman -S mingw-w64-ucrt-x86_64-gcc

This is where things get a bit weird. There’s different environments, and each one is different. It doesn’t appear to matter which one you use, really, but the default “ucrt64” is the one all the (barely existent) instructions use.

This command only installs gcc though. You’ll want gdb as well, plus make, autoconf and everything else. So you need commands like this

pacman -S mingw-w64-ucrt-x86_64-gdb
pacman -S make autoconf automake vim git

There’s a shell that gets installed, if you open it you can type in things like “gcc” and “gdb” to make sure they exist and work.

After that, the MSYS2 folders need adding to your path. The documentation explains this. If you get it right, opening a Windows Terminal (install that, don’t use cmd.exe, it’s not 1997 any more!) should let you also run gcc too.

Install VS Code

Grab VS Code from its website, install it. You then want to install the following extensions

  • The C/C++ Extension from Microsoft
  • Makefile Tools by Microsoft

The second one will give you an extra icon on your sidebar, and then VS Code understands makefiles. Alternately, just pop open a terminal and type “make”.

Install SDL

Download the latest release of SDL, and marvel at how it’s still in active development. I was half expecting this to be a dead project and the whole world to have moved onto monoGame or something in C#. But no, we can still use C++ and write code using SDL like we did 20 years ago.

Yes, the Lazy Foo website is also still being updated. I bet you the NeHe OpenGL site is still working as well.

Installing SDL is easy, unzip it, move the zipfile’s contents into your MSYS2 user’s home directory so the build tools don’t have a panic attack. Then build it like normal

./configure make make install

Do the same for any SDL libraries you need.

Write code!

That’s it, it “should just work” like it does under Linux. The Lazy Foo website has an example Makefile, and the projects worked last time I tried them.

Related Content