Visual Studio

I have spent the last 7 hours trying to get the SDL library to work for my Visual Studio. And I have seriously tried everything and I feel so hopeless. I've looked on youtube. I've looked at websites and I have no idea why it does not work. Can anybody please please help me?
When you download SDL there should be an include folder and a lib folder. You have to add these in your project settings and then link against the sdl2.lib.

Go to Project->Properties then Configuration Properties->VC++ Directories. Add the SDL\include under Include Directories and SDL\lib\x86 or SDL\lib\x64 under Library Directories.

Still in project properties go to Configuration Properties->Linker->Command Line and type "sdl2.lib" in the box. OR put this line somewhere in your code:

#pragma comment(lib, "sdl2.lib")

You have to do this for both debug and release builds.

Thank you so much for your suggestion. I've tried that. And I get the following error:

Error 2 error LNK2019: unresolved external symbol _SDL_main referenced in function _main

Anyway to fix this?

Also, I'm not sure what you mean by both debug and release builds.
Last edited on
Not really sure about that error as I don't use SDL, but the SDL faq says this:

I get "Undefined reference to 'SDL_main'" ...

Make sure that you are declaring main() as:

#include "SDL.h"

int main(int argc, char *argv[])

Also you should probably copy the SDL dll to your project folder.

If you look at the top of the VS window there should be a dropdown box that says "Debug" by default. It means you're doing a debug build which adds a lot of information to aid debugging in VS. It also uses a different configuration than Release mode. So when you switch to release you have to set the properties again.
Step by step tutorials here - from setting it up in Visual Studio to programming android apps
Registered users can post here. Sign in or register to post.