Making SDL2 and gcc 5.2 work together on Windows

For the past weeks I’ve been trying fruitlessly to make SDL2 work with my current setup. I just bought CLion and I was eager to test it – however, I also wanted to remind myself why I got into programming in the first place, and that reason is “writing games”. Which I never have done.

I’m also a huge fan of the developments in the C++ programming language – and I want to keep myself up-to-date with the latest and greatest additions. However, that felt impossible – mostly because CLion only works with gcc or clang compilers, and with things like cmake.

Initially I was a huge fan of cygwin. All’s fun and games with cygwin – I remember I tried to write an arkanoid game with SDL2 last year and I stopped due to more pressing issues at work, and cygwin was just amazing. It worked.

Well, this year, cygwin decided that everything SDL will require X11, and all of a sudden nothing works out of the box anymore. And while this allows for more things to be ported to Windows, this also annoys me greatly, because Cygwin’s X11 is really not well integrated with Windows – and it suffers a lot from the faults that I keep writing about and people insist that it’s not true, that I don’t understand the UNIX mindset.

So cygwin, although it keeps the compiler up to date like I want it to and all the tools updated properly, it lacks the main thing I need – a portable graphics system that will not be an overhead. Seriously, with X11 on Windows I get around 100 frames per second where directly with SDL and ‘the direct way of doing things’ I get 5000+, and the numbers are kept low because I log some stuff to the console.

So after quite a search I found the solution I desperately needed – that’s MSys2 with SDL2 and the latest GCC – here’s how.

First, download the MSys2 installer, run it, install it. Then the magic command is:

  1. `pacman -Su` – to update the core (if this does anything stop the terminal instance and start a new one)
  2. `pacman -S git mingw-w64-x86_64-toolchain mingw64/mingw-w64-x86_64-SDL2 mingw64/mingw-w64-x86_64-SDL2_mixer mingw64/mingw-w64-x86_64-SDL2_image mingw64/mingw-w64-x86_64-SDL2_ttf mingw64/mingw-w64-x86_64-SDL2_net mingw64/mingw-w64-x86_64-cmake make`

It will download a lot of stuff, but here’s the trick. git is git, you know what it does – the magic is in the mingw-w64-x86_64-toolchain, which has the latest gcc (and g++, of course). Then you install SDL2 as usual. The headers will be installed in the /mingw64/include/SDL2 – and you will have to link mingw32 as well when you link against SDL2.

Now, finally, I have no excuse to not start my game-ladder that I wanted to do from the first time I laid my eyes on CLion. And, btw, CLion is kind-of cool. 🙂


6 Replies to “Making SDL2 and gcc 5.2 work together on Windows”

  1. Dorin Lazăr

    I’m a bit confused by the ownership model for SFML – I’m never sure when the operation I make will add an overhead or not. SDL2 is indeed hard(er) to integrate with C++, but at least it’s clear who owns what and if you can keep the data in a container or not, or if you want to worry about copying too much data. But other than that I didn’t test it in too much depth.

Comments are closed.



Uniunea Europeană vrea să vă informez că nu vă folosesc datele personale pentru nimic. Și o fac aici.