JMU JMU - Department of Computer Science
Help Tools
Installing SDL for MinGW

1 Introduction

According to the SDL WWW site "Simple DirectMedia Layer is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware".

This document describes how to install SDL v2 on MS-Windows for use with MinGW. It assumes that you have already installed MinGW.

2 Getting Started

The first thing you need to do is download the development libraries for the MinGW port of SDL v2.

Then you need to extract everything from the compressed archive. (If you have installed MSYS you can use gunzip and tar. If not, you should install the GNU utilities for Windows available from the "Unix-like Utilities page".)

3 Putting Files in the Right Place

You need to copy several files to complete the installation.
  1. Copy the .a files from the appropriate lib directory to the MinGW\lib directory (the exact location of which will vary depending on where you installed MinGW).
  2. Copy the SDL directory from the appropriate include directory to the MinGW\include directory (the exact location of which will vary depending on where you installed MinGW).
  3. Copy SDL2.dll from the appropriate bin directory to the directory where your executable will be created.
    (Note: You can actually put SDL2.dll in any directory in your path. However, this may cause version conflicts if you have installed any applications that use SDL. So, it's safer though less elegant to just put SDL2.dll in the same directory as your executable.)

4 Building an Executable

You need to be aware of the following:

5 Testing Your Installation

You can use the following small program (named test.c) to test your installation:

You should be able to build this program from the command line as follows:

  g++ -o test.exe test.c -lmingw32 -lSDL2main -lSDL2

6 Using jGrasp

Some of you may have used MinGW under jGrasp in the past. You can do so with SDL but you will have to change some settings in jGrasp.

In jGrasp, choose Settings on the main menu, pull down to Compiler Settings, and then pull down to either Workspace or Project. Next, click on the Compiler tab and change the "Language" to C.

From here, you can set the "FLAGS or ARGS" for "Make", the "Compiler", etc... See, for example, the flags and arguments used in the example above.

Copyright 2019