Sign in to follow this  
lotios611

Game Engine Error with SDL

Recommended Posts

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.

Share this post


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

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


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

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