Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
msys2 sdl2 setup

Download and install msys2 64bit

Update msys2

  • Update msys2 64bit after install by running pacman -Syu if pacman needs to be updated you might have to close and reopen the terminal and run pacman -Syu again

Install build tools

  • 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

Compile Hello World


#include <stdio.h>
#include <SDL2/SDL.h>

const int WIDTH = 800, HEIGHT = 600;

int main(int argc, char *argv[]) {
  SDL_Window *window;
  SDL_Renderer *renderer;
    printf("SDL_Init failed: %s\n", SDL_GetError());
    return 1;

  window = SDL_CreateWindow("Hello, World!",
                                        WIDTH, HEIGHT,
  if(window == NULL) {
    printf("Could not create window: %s\n", SDL_GetError());
    return 1;
  renderer = SDL_CreateRenderer(window, -1, 0);
  SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);

  SDL_Event event;
  while(1) {
    if(SDL_PollEvent(&event)) {
      if(event.type == SDL_QUIT) {


  return 0;

Compiling with mingw64

gcc -o hello -Wall hello.c `sdl2-config --cflags --libs`

This comment has been minimized.

Copy link

@s10g s10g commented Mar 11, 2020

Thanks bro


This comment has been minimized.

Copy link

@jmgbsas jmgbsas commented Dec 22, 2020

I believe sould be gcc -o hello -Wall hello.c -l "sdl2-config -cflags -libs"
but I get error too ...
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot fi
nd -lsdl2-config -cflags -libs
collect2.exe: error: ld returned 1 exit status
I willsearch for sdl2-config
(windows MSYS2 msys64/mingw64 and 32)
I had succefuly compilation with:
gcc hello.c -o hello $(pkg-config --cflags --libs sdl2)
or for c++
g++ sdltest.cpp -o outsdl $(pkg-config --cflags --libs sdl2)


This comment has been minimized.

Copy link

@s10g s10g commented Dec 23, 2020

sdl2-config is a command

The stuff between `` (like sdl2-config --cflags --libs) returns on stdin the output from running the command `sdl2-config --cflags --libs`.

$ sdl2-config
Usage: /mingw64/bin/sdl2-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--libs] [--static-libs]

As you can see here, sdl2-config is merely an SDL2 provided command to make it easier to fill in the compiler options:

$ sdl2-config --cflags --libs
-I/mingw64/include/SDL2 -Dmain=SDL_main
-L/mingw64/lib -lmingw32 -lSDL2main -lSDL2 -mwindows

So the reason you're getting an error is.... oh I see you already edited it 👍


This comment has been minimized.

Copy link

@jmgbsas jmgbsas commented Dec 24, 2020

ok sdl2-config is a command .... for that reson is the character ` ...I believed was an option and changed for " , I will see
Thanks, happy New Year !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment