Wednesday, July 11, 2012

Lesson 0: Setting up SDL

SDL 2.0 Note

SDL Release Update: Now that SDL2 is out (hooray!) I've put an updated setup guide over here.


As of the time of writing this post, July 17, 2012 the SDL 2.0 libraries have not been officially released and as such you will need to compile them for yourself with your editor of choice.

You may download the libraries from here.

Cloning from the Mercurial directly will get you an up to the minute version and while the snapshots are also a fine alternative, at the time of writing you need to clone the Mercurial repository in order to download snapshots of the extension libraries we will be using later in this tutorial.

After downloading the repositories setup should be reasonably straightforward. Note that the extension libraries SDL_image, SDL_ttf and SDL_mixer depend on SDL and as such you may need to specify include directories or linker settings for them to compile and SDL should be compiled first.

Note that the source folders contain documentation on how to build them with each platform which should take you through building and confirming that everything works, or you may continue reading.

When SDL 2.0 is officially released I'll update to simply link to the locations where you can download the pre-compiled libraries, which is far easier.

C++11 Note

Throughout this tutorial we will be using a few of the new features provided by the new C++11 standard and as such you may either use a compiler that supports these features, or translate the code to features that are supported by your compiler, which shouldn't be too much of a pain. Visual Studio 2012 has C++11 support, and if using GCC you may specify enabling of C++11 features by adding -std=c++0x to your compile flags.

Visual Studio

The source folders should contain a folder titled VisualC, if you are prompted to update the project upon opening, do so. Before building the solution make sure you have selected to build the Release version. From here the solution should build smoothly. The main directory also contains an instruction file called VisualC.html that contains some helpful information if you have trouble compiling.

When building the extension libraries be sure to build the Release versions. Note that before you're able to compile you will need to specify include and library directories for your SDL2.0 files.

SDL_mixer Note: Unfortunately I was unable to build SDL_mixer under Visual Studio, although it did work under Linux, so I think there's some issue related to the Visual Studio project.

Once you've built all the libraries put the header files, lib files and dlls somewhere you won't forget, as we'll need to use these files in our projects. My location of preference is C:\

The guide for creating your first SDL project with Visual Studio is found here.


Linux users simply follow the standard configure, make, make install pattern. Make sure to record the path that the header files and libraries where installed too, as you may need to specify the path when compiling. Alternatively you can move the libraries and headers to the standard location. You must also place or link the runtime libraries to /lib/ or a similar alternative location where your runtime libraries are stored.

The Linux command line tutorial continues here.


The source folders also come with a project for XCode however I don't have a mac and unfortunately am unable to provide further guidance. Check the included documentation for instructions on building the libraries and how to include the headers and libraries in a project.


  1. Bear SDL 2.0 is officially released so please update the tutorial(s) accordingly. Btw learned a lot from these nice tut's ;)

    1. Yep I've been working on an update to the series but I'm also migrating sites since Github pages is a lot easier to work with for embedding code. The new lessons can be found here:

  2. Since comments are not working on the github page. I will post this here. I setup the project just as you have done in the tutorial the problem is that once I run the executable that is built either through Visual Studio 2012 or by double clicking the exe in the output directory. It hangs completely. I see the window console window show up and then go away but it is still in the process list as running and if ran through visual studio visual studio is now hung. I can kill the devenv process and visual studio window goes away but the process is still there, cannot kill it or the SDL_Tutorial process. This is with debug or release. I have to restart to be able to use visual studio with that project again. If you have ever seen this what can I do to fix that. I am new to SDL and have very little C++ experience so I might have missed a something. Tried the Next Hello World program just to make sure and it did the same thing so I am sure it is something in my settings but not sure what at this time

    1. Oh yea, you shouldn't comment on the Github page, just on the blog posts heh.

      That's a very strange issue, perhaps try looking at my updated series over here: ? Or maybe even just try running a basic hello world program like

    2. Oh whoops, one thing I forgot to mention. Make sure you've copied the SDL2.dll binary into the same directory as your executable. I guess you can't edit comments on blogspot? Wierd.

    3. I am trying to get more debug to find out. I went through the Lesson 0: Visual Studio and what I got was the problem I described above. So I thought I would put a break point at the first line in the main and it doesn't even make it there. So I will try a few other things.

      I can make more than just a simple helloworld program normally. I have few other programs that I have coded up both C# and C++ none using SDL. I have not used C++ for a while so I am a bit rusty. So I think that I messed up one of the settings or something. The last time I ran it now console window popped up. Hard to do anything because as soon as I run it I have to restart my computer to do anything else in Visual Studio with that project.

      So I will post again once I go through the tutorial again and make sure I go step by step and not skip anything. Thanks for the reply.

    4. If it's not even making it to the first line of main it sounds like you don't have the required dll in the same folder as your executable, you should have SDL2.dll in the same directory as your program for it to run properly. If you do get it working you should use the lessons on my github page, as I've improved the code and lesson text quite a bit.

    5. If you don't have a dll at all, you get an error message saying that the dll is not installed on your system. I am going through the to tutorials on the github page, just can't comment over there. I thought maybe since i put a post build command to copy over the dll, I grabbed the wrong version(64 instead of 32). So I took the new project and manually copied over the 64-bit and I got a different error. So I have to screwed something up in the settings somewhere.

      Thank you so very much for these tutorials.

      Hopefully I don't have to many more stupid problems. I think there was something wrong with the xcopy command I put in the post build events. So I will just copy it manually, so I don't have to worry about it. After I get enough I will add in the xcopy again and see what I did.

      Again thanks.

    6. Okay just in case you ever here of a similar problem. It was Avast's DeepScreen that was causing the problem. I had it turned on silent mode so I never saw the message. Also shows how impatient I am cause I didn't give it enough time to scan it all the other times. Got to remember to turn that stuff off while coding.

    7. Oh pesky anti-virus hehe. Odd that you can't comment on the github pages, I thought I enabled guest/anonymous comments on Disqus. Good to hear you got it working!