Setting Up SDL2 with Visual Studio 2012 and 2013

Setting Up SDL2 with Visual Studio 2012 and 2013

I have confirmed that everything below works for Visual Studio 2013.
Links updated to the latest release (2.0.3).

The Simple DirectMedia Library (SDL) version 2 has been released after a long time in development. It seems that the author has more time on his hands and more corporate backing from his new position at Valve Software. I’ve heard that they use SDL for various small time projects that don’t require heavy rendering. Even so, SDL does a formidable job at making things easy.

I wrote this guide under the following setup, but I’m sure that it can be applied to other version of Windows (and maybe even Visual Studio).


Anyway, try your setup and let me know how it goes. Follow these steps to get all setup and ready to code:

  1. Download the development libraries
  2. Download the 32-bit binary or the 64-bit binary
  3. Extract both zips to a convenient location
  4. Open Visual Studio and create an empty C++ project
  5. Right click the created project in the Solution Explorer, go to Properties
  6. Click VC++ Directories under Configuration Properties
  7. In the “Include Directorires” line, add the include directory from the extracted development library
  8. In the “Library Directories” line, add the libx86 directory from the extracted development library
  9. Click Linker –> Input under Configuration Properties
  10. In the “Additional Dependencies” line, add “SDL2.lib” and “SDL2main.lib” strings
  11. Click Linker –> System under Configuration Properties
  12. In the “SubSystem” line, change the selection to WINDOWS(/SUBSYSTEM: WINDOWS)
  13. Finally, copy the SDL2.dll file from the extracted 32-bit binary folder to your project’s output directory alongside the executable

OK, the ugly project setup is finished. Now we can have some fun with coding. Now add a new cpp file with this code.

Compile and run the application to see if any errors are generated. All we did in this code was initialize SDL and immediately quit. If you saw any strange errors, then something is either wrong with the project properties described above, or you’re missing some SDL dependencies.

12 thoughts on “Setting Up SDL2 with Visual Studio 2012 and 2013

  1. After doing a rebuild I get a linker warning:

    Warning 1 warning LNK4098: defaultlib ‘msvcrt.lib’ conflicts with use of other libs; use /NODEFAULTLIB:library C:Tempvisual studio 2012ProjectsSDL_testSDL_testMSVCRTD.lib(cinitexe.obj) SDL_test

    Have you found a way to fix this?

      1. As far as I can tell, this is caused by SDL2main.lib building against msvcrt (the multi-threaded DLL CRT) and NOT msvcrtd (multi-threaded /debug/ DLL CRT). Visual Studio sets up Debug builds as building against MSVCRTD by default. Fix: Building against the non-debug CRT, I guess. Not ideal.

  2. I ran into this using Visual Studio 2010 and found the answer here: http://wiki.libsdl.org/FAQWindows

    > When using Visual C++ I get link errors relating to MSVCRT.LIB or LIBC
    > SDL is dynamically linked with the multi-threaded version of the Microsoft Visual C runtime. You need to edit your project settings, go to the C++ language tab, change the listbox to “Code Generation” settings, and then change the runtime library to “Multi-threaded DLL”. Make sure you do this with all projects that you link into your application.

  3. Thank you so much, this actually works, and your instructions are great. Yesterday I spent an hour and a half looking through and trying instructions that didn’t work for me. And I also realized that I had to put “return 0” in main, lol. Can’t wait to start using this library.

    1. Just kidding, now it doesn’t work at all and cannot read a bunch of essential dll’s. I’ll think that I’ll use my mac for what I’m trying to do, instead.

  4. I’ve gotten through most of the setup process but have no idea where to put the SDL2.dll file. Does it go in the project folder in my Documents section? Or do I have to link somehow through VS 2013? Thanks!

    – Mauro

    1. Hi Mauro. When you build and compile your project with Visual Studio, you should get an output executable file. Put the SDL2.dll file in the same directory as your executable.

      1. Okay, I had to try and build the application at least once to get the debug folder to be created in the main project folder. Compiled and didn’t get any errors after placing the dll in the debug folder. Thanks for posting this tutorial! 🙂

Leave a Reply to MrPhil Cancel reply

Your email address will not be published. Required fields are marked *