Setting up a Code::Blocks Project with SDL on Windows

I’ll show here how to get the Code::Blocks IDE up and running for SDL development on Windows using the Classic Invaders source as an example.

Code::Blocks is an open source, cross platform, free C++ IDE.

Go to this page and download the codeblocks-10.05mingw-setup.exe file.

Install Code::Blocks and then download the following:……

Go to and download the latest version of the boost C++ libraries.

Extract the archives and put them in the same folder (just to be organized).

Launch Code::Blocks. Click the “Create a new project” link or go to File->New->Project. In the “New from Template” dialog select “Empty Project” and click Go.

Give the project a title, choose a location, and click Next.

Then click Finish.

Copy all the Classic Invaders source files (or your own source) into the directory where the project file is stored (again this is just an organizational choice, the source can be stored elsewhere) and then Go to Project->Add files… and select and add all needed source files.

Select both Debug and Release as the targets the files should belong too.

You should now see the source files on the left pane of the Code::Blocks IDE like so

Now to set the Project options and the locations of the headers and libraries.

Go to Project->Properties… and select the Build Targets tab. For both build targets change Type from Console Application to Gui Application.

Next go to Project->Build options… and select the project name on the top left so the settings put here will apply to both the Debug and Release builds.

Select the “Search directories” then “Compiler” tab and add the include directories

then with the “Search directories” tab still selected select the “Linker” tab and add the library paths

then select the “Linker Settings” tab and add the following to “Other linker options:”

-lmingw32 -lSDLmain -lSDL -lSDL_image -lSDL_ttf -lSDL_mixer

then click OK.

At this point the program will build but it will not run until we put the runtime dlls and the data into the correct locations. If you try to run it you will most likely get a dialog saying the SDL.dll cannot be found (unless you have it in a system directory on the path). Error messages that you output in your program are written to a file (stderr.txt) in the same directory as the .exe.

The working directory when running a program from within the Code::Blocks IDE is the directory that the project file (*.cbp) is stored in. Copy the data directory from the Classic Invaders source and the following dlls


into that directory. It is convenient to have this as the working directory because Debug and Release targets can be run without having to have the data and dlls in two locations. When you run the .exe directly by double-clicking it, the working directory is the directory the .exe is in, so the dlls and data would need to be located there when launching the program outside the IDE.