To build the projects with mingw we’ll be using a lightweight makefile that will set the
include and library paths along with linking our dependencies for us. The makefile assumes
that you’ve placed the SDL mingw development libraries under
C:/SDL2-2.0.0-mingw/ and that
you’re using the 32bit version of mingw and the 32bit libraries. You should change this to
match your compiler (32/64bit) and the location of your SDL folder. To use makefiles with mingw call
mingw32-make.exe in the folder containing the makefile.
If you’re unfamiliar with Makefiles a basic introduction can be found here.
This makefile is configured to build our project with a console alongside the window since
we’ll be writing our error and debug output to stdout.
If you want to use a better file logging method or distribute your program and not have
a console open up you’ll want to remove the console flag (
-mconsole) from the linker flags.
The program we’re building for this lesson is a simple sanity check for SDL. It will
initialize the SDL video subsystem, check for any
errors and then quit.
The source file should be titled
main.cpp, or you can change the main.o build dependency
in the makefile to match your source file. Before we can run this program we’ll need to copy the SDL
binary into our executable’s directory. SDL2.dll can be found in the bin directory in the mingw folders,
you should use the one for the architecture you compiled for (32/64bit).
The program should run successfully but nothing should appear to happen if you’ve configured everything properly. If an error occurs make sure you’ve followed all the setup steps properly.
If you’re having any trouble setting up SDL please send an email or tweet.
I’ll see you again soon in Postscript 0: Properly Finding Resource Paths!