External Main Function

Started by
4 comments, last by SiCrane 16 years, 3 months ago
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?
Advertisement
You have to link against that project when building your application.
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.
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.
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?
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.

This topic is closed to new replies.

Advertisement