Jump to content
  • Advertisement
Sign in to follow this  
poss74

Problems with SDL

This topic is 4842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, I've been at this for a couple of hours, and I've managed to resolve a couple of issues, but I'm at the end of my tether with this one. I'm just starting playing around with SDL in VC++6, and I've got a very simple main.cpp file (from the Devmaster wiki):
#include "SDL.h"

#define FAILURE 1
#define SUCCESS 0

int SDL_main(int argc, char* argv[]) {
	if (SDL_Init(SDL_INIT_VIDEO) < 0)
		return FAILURE;

	SDL_Surface* Screen = NULL;

	Screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);

	if (Screen == NULL)
		return FAILURE;

	SDL_Quit();
	return SUCCESS;
}

But when I go to run the program, I keep getting these error messages:
Quote:
Compiling... Main.cpp Linking... Main.obj : error LNK2001: unresolved external symbol __chkesp LINK : error LNK2001: unresolved external symbol _mainCRTStartup Debug/Pong.exe : fatal error LNK1120: 2 unresolved externals Error executing link.exe. Pong.exe - 3 error(s), 0 warning(s)
I've tried googling the answer, but I haven't found anything relating to __chkesp, and the only thing relating to _mainCRTStartup said to make the set the runtime library option to Multithreaded DLL (which I have -- no effect). Any help here would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
You must link two libraries: SDL.lib AND SDLmain.lib.

Your main program body must be:

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

}

as usual.

And indeed you must link with multi-theaded DLL runtime.

Link those 2 libz above, use main and it should work.

Share this post


Link to post
Share on other sites
Yes like he said you basicly need to link to SDL.lib and SDLmain.lib and link with multi-theaded DLL runtime. Else it will forever give you linking error.

To include the library opent he project propriety. Go to Linker the command line and in the addiotional options write down

SDL.lib SDLmain.lib

Edit : Just realized that you use VC6. i can't tell you how to add the lib, but that should be similar.

Share this post


Link to post
Share on other sites
Thanks, but that didn't work. I already had SDL and SDLmain linked in (it's in Project|Settings, Link tab) and changing SDL_main() to main() had no effect either.

I've double-checked that everything's in the right place, that my SDL library and include folders are in the right place, but I still can't get the dratted thing to run.

Any more suggestions?

Share this post


Link to post
Share on other sites
Hmmmm...why have you got SDL_main() explicitly included in your code.

The SDL header (SDL.h) has a macro that subsitutes main() for sdl_main(). Try changing in back:

from:

int SDL_main(int argc, char* argv[]) {.....

to:

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

Also use <SDL.h> or <SDL/SDL.h>...if your include paths are set up correctly that is.

Share this post


Link to post
Share on other sites
If its possible for you to upload the project (workspace, files, resources, etc) I can pop it open and see what's going wrong. But a linker error is definitely due to it not being able to figure out what's going on at the entry point - all the obvious fixes have already been mentioned:

- Code Generation: Multithreaded DLL
- Libraries linked properly
- int main(int argc, char* argv[])

Quote:
Also use <SDL.h> or <SDL/SDL.h>...if your include paths are set up correctly that is.

A problem like that will raise a compile error, not a linker error.

Share this post


Link to post
Share on other sites
Quote:
Original post by garyfletcher
Hmmmm...why have you got SDL_main() explicitly included in your code.

persil already suggested that above. Changing it to int main() has no effect, I still get the same error messages.

Quote:
Original post by ukdeveloper
Did you use VC++ to make a Win32 Console app or a plain Win32 app?

Win32 Console app. I'm following the instructions in the Devmaster wiki to the letter.

Quote:
Original post by Mushu
If its possible for you to upload the project (workspace, files, resources, etc)...

Yup, but you'll have to wait a few hours, since I'm currently at work (won't get home for another 9 hours) [sick]

Share this post


Link to post
Share on other sites
Quote:
Original post by Mushu
If its possible for you to upload the project (workspace, files, resources, etc)

Dang, how and where do I upload the project file?

Share this post


Link to post
Share on other sites
Yahoo, fixed it! Turned out I needed to turn OFF the "Include all default libraries" option.

Thanks to everyone who contributed to this thread, I've rated you all up [grin]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!