Lazy Foo' Productions

Setting up SDL in Code::Blocks

Last Updated 11/02/09
1)First thing you need to do is download SDL headers and binaries.
You will find them on the SDL website, specifically on this page.

Scroll Down to the Development Libraries section and download the Mingw32 development library

Open gz archive and there should be a *.tar archive inside.
Open the *.tar and there should be a folder inside of that.
Copy that folder anywhere you like. For these tutorials I'm putting it in C:\

2)Start up Code:Blocks and go to the Compiler and Debugger settings.

3)Go to the Compiler tab under Search Directories. Click add:

then add in the include directory from the SDL folder you extracted.

4)Then under the linker tab add in the lib directory from the SDL folder:

5)Now take the SDL.dll from the SDL folder you extracted (it should be inside the bin subfolder) and copy it to where you're going to make your project. You're going to put SDL.dll in the same directory as your exe when you compile it.

Alternatively, you can copy SDL.dll to C:\WINDOWS\SYSTEM32 so your SDL app will find SDL.dll even if it's not in the same directory. If you're using a 64bit version of Windows, you'll want to put the dll in C:\Windows\SysWOW64.

The problem with this method is if you have multiple SDL apps that use different versions of SDL, you'll have version conflicts. If you have SDL 1.2.8 in SYSTEM32 when the app uses 1.2.13 you're going to run into problems. Generally you want to have your SDL.dll in the same directory as your executable developing and you'll always want to have SDL.dll in the same directory as the exe when distributing your app.

6)Now start up Code::Blocks and create a new empty project.
Then save the project where ever you want. I know Code::Blocks has an SDL project template, but I personally found it to be more combersome than doing things manually.

7)Next, go to the project -> properties.

8)Under the Build Targets tab, set Type to "GUI application". This is to make sure a console window does not pop up.

9)Go to the Compiler and Debugger settings again and under the Linker Settings tab paste:
-lmingw32 -lSDLmain -lSDL
in Other Linker Options
10)Add a new source file to the project with the following code:
#include "SDL/SDL.h" int main( int argc, char* args[] ) { //Start SDL SDL_Init( SDL_INIT_EVERYTHING ); //Quit SDL SDL_Quit(); return 0; }
Save the source and compile your project. If there are no errors, you're done. Otherwise go back and make sure everything is done. Double check that you have SDL.dll in the same directory as your exe or system32.
Also, In the archive you just downloaded there's a subfolder called "docs". It contains the SDL documentation.

I highly recommend that you extract them somewhere and keep it for reference.

Tutorial IndexPart 2: Getting an Image on the Screen