# SDL Trouble? Look Here.

## Recommended Posts

Having trouble with SDL? I know I sure did when first learning it! Not that I still don't, but I realized that most of my problems were very similar. I've also noticed that the majority of problems posted here are very similar. Below are the most common mistakes I see on posts made here and in my own experience. If you're having trouble getting your game up and running in SDL, go through these few things first. warning LNK4098: defaultlib "msvcrt.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
This happens when you forget to set your linker to use a multi-threaded DLL. This is a requirement for linking SDL unless you build SDL yourself.
Visual Studio.NET
• Make sure you have at least one .cpp file in your project. It can be blank.
• Right-Click on your project name in the Solution Explorer and select "Properties".
• Select "C/C++" and then "Code Generation".
error LNK2001: unresolved external symbol _SDL_main
This could happen for a couple of reasons. Most of the time it's because of the way the libraries need to be linked in the code. To resolve this, add these lines to your main source file, or to a header file linked into your main source file:
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
If this doesn't work, then you might have a very subtle and sneaky problem. This one hasn't bitten me, but I've seen it get others. When using SDL, you cannot have a void parameter list for your main function. You must use the command line variables.
int main(void) // Bad
int main(int argc char **argv) // Good
Everything compiles but the screen and/or a surface is blank
This one can be tricky once your program starts gaining size and you Separate your code. Make sure you initialize SDL's video system and set the video mode BEFORE attempting to render anything. The code to do this is:
SDL_Init(SDL_INIT_VIDEO);
/*YOUR_SCREEN_SURFACE*/ = SDL_SetVideoMode(WIDTH, HEIGHT, BPP, FLAGS);
It is imperative that you declare your screen surface before you do this.
Founts of SDL Knowledge

##### Share on other sites
Quote:

Actually; this is because sdl.lib includes other libraries that it shouldn't. Setting your own project to multi-threaded dll only works because then it doesn't also include those libraries. This is bad, as you end up using whatever library happened to be present when sdl.lib was compiled and not the possibly updated one available right now. The proper solution is to compile SDL yourself.

##### Share on other sites
Yes, but it works. I have a feeling people would rather do that than build their own. We are talking about SDL noobies, one of which I still am.

Edit: I adjusted the post, however, to be more accurate. (And now I'm going to build my own SDL. Thanks for the tip [smile])

##### Share on other sites
Over at the game programming wiki, we're attempting to be a "fount of SDL knowledge" too :)

Our SDL Tutorial page has a number of unique articles, and an extensive list of other helpful SDL sites!

##### Share on other sites
I say we all band together to promote and contribute to that Wiki [smile] I haven't been to that page in a looong time, niec to see the updates! I think I'll add some stuff as well

I'm on board!

##### Share on other sites
Vote for:

(x) Make it sticky!

Lots of newbies have those problems (even me had problems with those error messages). Perhaps we all could create a site with all those common openal/sdl questions (nothing oversized, just common problems)

I had no problem to help.

##### Share on other sites
Quote:
 Original post by Ludi83Perhaps we all could create a site with all those common openal/sdl questions (nothing oversized, just common problems)

That's what this site can be used for buddy [smile] Just a seperate section that has a list of all the bugs and stuff, then link to that specific page.

##### Share on other sites
Quote:
 Original post by Drew_Bentonbuddy

Yeah, you called me buddy ;)
Okay, but then make that post with the link to that wiki sticky (yeah, nice, how do you call that that in english (wiki sticky), we call it a Reim :D)

##### Share on other sites
 I see what you're asking now! We call it a "Rhyme". They are probably pronounced the same.

Yes, Drew has many buddies [smile]

As far as "wiki", it's not an English word. Well, it's in our dictionary now as the weblog thing, but it's actually Hawaiian, meaning "Quick".

##### Share on other sites
Quote:
 Original post by Drew_BentonI say we all band together to promote and contribute to that Wiki [smile]

That would be excellent! Any and all contributions are certainly welcomed :)

The wiki craves information!

##### Share on other sites
From past experience I've found that the error caused by forgetting to set the code generation options to multi-threaded dll is multiple defined symbols in the standard libs which will cause the build the fail - not a standard lib conflict which isn't fatal in itself.

Apart from that great job, I'm surprised no-one (including myself) hasn't thought of making such a thread before. Having a Wiki for this sort of information would be an invaluable source of information for new SDL users.

##### Share on other sites
Quote:
 This could happen for a couple of reasons. Most of the time it's because of the way the libraries need to be linked in the code. To resolve this, add these lines to your main source file, or to a header file linked into your main source file:#pragma comment(lib, "SDL.lib")#pragma comment(lib, "SDLmain.lib")If this doesn't work, then you might have a very subtle and sneaky problem. This one hasn't bitten me, but I've seen it get others. When using SDL, you cannot have a void parameter list for your main function. You must use the command line variables.int main(void) // Badint main() // Badint main(int argc char **argv) // Good

Oh yeah, this one is very familiar.

##### Share on other sites
Getting console output with dev-cpp is worth a mention.

##### Share on other sites
Quote:
 Original post by RhaalEverything compiles but the screen and/or a surface is blankThis one can be tricky once your program starts gaining size and you Separate your code. Make sure you initialize SDL's video system and set the video mode BEFORE attempting to render anything.

I dunno if anyone else ever does this, but usually when I get a blank screen, its because I forgot to call SDL_Flip() (or SDL_GL_SwapBuffers()) after rendering everything. That'd maybe be an interesting little tidbit to add to your excellent little mini-faq.

##### Share on other sites
I have one more week of long hard Uni. finals then I'm on summer vacation. During that time, I will start to add to the Wiki, I haven't forgotten about it!

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627707
• Total Posts
2978721

• 21
• 14
• 12
• 22
• 35