Sign in to follow this  
Rhaal

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".
    • Change "Runtime Library" to "Multi-threaded DLL" or "Multi-threaded Debug DLL".
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() // 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 this post


Link to post
Share on other sites
Quote:
This happens when you forget to set your linker to use a multi-threaded DLL. This is a requirement for linking SDL.


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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Ludi83
Perhaps 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 this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
buddy


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 this post


Link to post
Share on other sites
[edit] 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 this post


Link to post
Share on other sites
Quote:
Original post by Drew_Benton
I 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 this post


Link to post
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 this post


Link to post
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) // Bad
int main() // Bad
int main(int argc char **argv) // Good


Oh yeah, this one is very familiar.

Share this post


Link to post
Share on other sites
Quote:
Original post by Rhaal
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.


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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this