Game Engine Error with SDL

Started by
8 comments, last by lotios611 13 years, 4 months ago
I've been trying to develop a game engine using SDL but have hit upon a very simple snag. When I compile my game engine, it compiles and links fine but when I test it out in a game I get the linker error LNK1561. I am using VC++2008 Express on Windows XP SP3.
Advertisement
It is generally a good idea to post the full error message. It sounds like your main() function isn't correct (SDL requires the "two argument" form, or int main(int argc, char **argv)) or you aren't linking to SDLmain.lib.

Also, I would say it doesn't link fine if you are getting linker errors =]
Quote:Original post by rip-off
It is generally a good idea to post the full error message. It sounds like your main() function isn't correct (SDL requires the "two argument" form, or int main(int argc, char **argv)) or you aren't linking to SDLmain.lib.

Also, I would say it doesn't link fine if you are getting linker errors =]

Alright, here's the full error message:
Quote:LINK : fatal error LNK1561: entry point must be defined

And here's my main.cpp:
#include "SE_Engine.h"int main(int argc, char **argv){	SE::Engine engine;	return 0;}
It might be a smart thing to show us your initialization of the Engine class. Post the constructor and/or whatever other initialization functions you run so we can actually help you figuring out where it's going wrong when starting up your application.

Also, make sure to read this topic: http://www.gamedev.net/community/forums/topic.asp?topic_id=335101


Might give you a solution to your problem, the 'fixes' stated there are:

* Compile as "Multithreaded DLL" (Under project properties)
* Go to Project Properties, C/C++, Precompiled Headers and change the setting to not using precompiled headers.
If I've helped you in any way please push the reputation button, thanks!

Abstraction is my choice of words.
Portfolio: http://www.0x3a.com/
Blog: http://blog.0x3a.com/
You must include "SDL.h" directly or indirectly in the source file that defines main(). You must also link to SDLmain.lib.

This is because SDL provides a system specific main() function (where appropriate). For example WinMain() on Windows. To do this, SDL uses a macro to change your main() into a function SDL_main(). Then its system-specific main() calls SDL_main().

Are you linking to SDLmain.lib in addition to the normal SDL.lib?

Quote:
It might be a smart thing to show us your initialization of the Engine class. Post the constructor and/or whatever other initialization functions you run so we can actually help you figuring out where it's going wrong when starting up your application.

Not necessary - this is a linking issue and will not be caused by initialisation code (or lack thereof).
Quote:Original post by rip-off
You must include "SDL.h" directly or indirectly in the source file that defines main(). You must also link to SDLmain.lib.
I included SDL.h in my SE_Engine.h and have linked SDLmain.lib in my engine. Do I need to link it in my game too?

Is your engine in a DLL? You need to link to SDLmain.lib in your executable, or provide your own entry point (e.g. WinMain()).

Alternatively, you could add another level of indirection and add your own library, SE_main.lib, which is linked to SDLmain.lib. This way your engine users won't be aware of the dependency on SDL (although if you #include SDL.h in your own headers then they will be forced to have SDL installed anyway).

It is probably legal to simply rename SDLmain.lib as SE_main.lib, but you'd need to double check - IIRC SDLmain.lib is released under a very permissive license to allow it to be used in commercial applications.
My engine is a .lib. I don't mind having the user knowing the dependency on SDL, it's just that I don't want them too have to link to my engine and SDL.
I believe if you link your engine.lib to SDLmain.lib it should work. Have you actually tried it yet?
Yes, my engine.lib should be linked with SDLmain.lib. It could be something wrong with the way I set up my engine. I first change the settings to compile as an .exe and then I set my linker settings. Than I change it back to compiling as a .lib. I don't know any other way to set the linker settings on a .lib project in VC++2008 Express. I've uploaded a compressed .rar of both my engine and my test game to rapidshare.

[Edited by - lotios611 on December 7, 2010 4:49:09 PM]

This topic is closed to new replies.

Advertisement