Sign in to follow this  

External Main Function

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

This topic is 3628 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.

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