How to Install SDL Under MinGW on Netadelica


SDL is great and it lives here. But if you're not already a guru, it can be difficult to install, and there aren't many if any step-by-step instructions for getting it working. So, if you're struggling to install it under MinGW, this page might be helpful.

Installing SDL

These are the steps I took to get SDL 1.2.9 running, starting with MinGW and MSYS already installed, and using Windows 2000.

Download and unpack SDL

Install SDL files for the compiler

Copy the SDL DLL and tidy up

You should now have a working SDL installation and you can write some code.

Your First SDL program

Here's a small program to get started and to test everything's working.

#include <stdio.h>
#include "SDL/SDL.h"
      // include the SDL headers you put in /mingw/include/SDL/

int main(int argc, char *argv[]) {
      // with SDL, you need the argc and argv parameters

  printf("Hello world\n");
        // with SDL, anything you printf will get printed to the
        // file stdout.txt in the current directory, not to the screen

How to Compile an SDL program

To compile an SDL program, use this:

gcc filename.c `sdl-config --cflags --libs`

Note that you use backticks, not normal apostrophes. The file sdl-config will get executed (which is why you copied it to /msys/bin/ so that you can be sure that it will get executed) and will pass its output to gcc, in a sort of magical ritual that I don't understand.

If you compile the above program, then you should see no error messages or any other output from the compiler. You should be left with an exe file in the current directory (a.exe by default) which when run will create stdout.txt and write "Hello world" to it. To learn how to do graphics and that, see the SDL Web site.

Back to the Netadelica home page

1 Sep 2005