Jump to content
  • Advertisement
Sign in to follow this  
Uphoreum

External Main Function

This topic is 3913 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

I have another question regarding my engine-ish library I'm working on. I'm trying to make a different entry point for applications that use the engine, similar to how SDL uses WinMain internally, but calls the function 'main' from it, which is a function that the application that uses SDL defines as it's entry point. I looked through SDL's header and found that it defines main as 'extern', so I tried doing that with my library, but when I tried to compile the library, it told me that it was an unresolved external symbol. Is there something else I need to do to specify that that function is defined in a separate project?

Share this post


Link to post
Share on other sites
Advertisement
Well, my problem is with compiling the DLL itself. I can't link with the project that uses the DLL, since that project isn't a library.

I have the engine's entry point defined as 'extern int GBMain(int argc, char *argv[])' in the main engine header file, then in one of the engine's source files, I have SDL's main function simply call the engine's main function, which is to be implemented by the application:

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

I guess I'm doing something wrong though, because when compiling the engine, the engine still wants to have an implementation for GBMain. I thought the 'extern' keyword would allow it to compile fine and then when the application implements GBMain linked with it, the engine would use the application's GBMAin function like SDL does with the SDL_main/main function.

Share this post


Link to post
Share on other sites
Well, the basic problem is that you can't do that with a DLL; you need a static library. This is why SDL has both SDL.dll and SDLmain.lib.

Share this post


Link to post
Share on other sites
Oh, you're right, SDLmain is a static library. I didn't even think about that.

Well, maybe I should just focus on the root of this whole problem. The reason I was going to try to do this was because I want to be able to have my applications link just with the engine itself and not all it's dependencies. If I don't link with SDLmain however, it gives me a linker error about WinMain@16 (even though the engine DLL links with SDLmain).

If I link with SDLmain, this error goes away. It seems that SDLmain's implementation of WinMain doesn't carry over. Why would this be and what should I do about it?

Share this post


Link to post
Share on other sites
Entry points need to be part of the executable module. Linking your DLL against SDLmain.lib puts WinMain in your DLL, not the executable, and DLLs are separate modules.

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!