Lazy Foo' Productions

Setting up SDL in Visual Studio.NET 2003

Last Updated 2/18/12
Before you start, make sure you have the Visual Studio 2003 service pack properly installed. If you don't, SDL will not work with Visual Studio.NET 2003. I have a mini tutorial to properly set up VS.NET available here.
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 Windows development library

Open the zip and there should be a folder inside of it.
Open the folder and it'll contain a bunch of subfolders.

2)Next go to the Visual C++ include folder and create a folder called "SDL". The Visual C++ include folder should be at C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\Include.

3)Then open the include subfolder in the archive and extract its contents to the folder you just made, which should be at C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\Include\SDL.

4)Copy SDL.lib and SDLmain.lib from the lib subfolder in the archive to the Visual C++ lib folder. The Visual C++ lib folder should be at C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\lib.

For certain versions of SDL, there will be a x86 folder and a x64 folder inside of the lib folder from the archive. The x86 folder contains the 32bit *.lib files and the x64 bit folder contains the 64bit versions of the library files. If you're compiling a 32bit program, copy the the *.lib files from the x86 folder and if you're compiling a 64bit version get the library files from the x64 folder. By default Visual Studio compiles in 32bit so if you're not sure how you're compiling, try the 32bit libraries first. What matters here is not whether you have 32/64bit windows, but what type of program you're compiling.

5)Now take the SDL.dll from the archive (it should be inside the lib subfolder) and extract it. You're going to put this in the same directory as your project/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.

7)Now start up Visual Studio and start a new Win32 project:
and click ok.

8)Make sure it's an empty project by going to the application settings:
and checking "Empty Project" so nothing is automatically generated.

9)Then add a new source file to the project:

10)Now paste the following code into your new source file:
#include "SDL/SDL.h" int main( int argc, char* args[] ) { //Start SDL SDL_Init( SDL_INIT_EVERYTHING ); //Quit SDL SDL_Quit(); return 0; }
and save the source file.

11)Next go to project settings.

12)In the C/C++ folder under Code Generation, set "Runtime Library" to multi-threaded dll.

13)In the Linker folder under Input, paste:
SDL.lib SDLmain.lib
in the additional dependencies field.

Now Build. Make sure SDL.dll is in the same directory as the project/executable. If there are no errors, you're finished. Otherwise go back and make sure you didn't skip a step.
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 Index Part 2: Getting an Image on the Screen