简体   繁体   中英

Do I need SDL's main() function?

I'm looking at possibly using SDL2 from my own private languages. They can talk to dynamic libraries such as SDL2.dll so it might be feasible. But first I need to try it out using C.

But, a hello-world style of tutorial was elusive (they're for the wrong version of SDL, or they're in C++ or whatever). Finally however I put together a minimum program (just #include "sdl.h" and main(){} will show the problem), and I can't link because I don't have main() or WinMain().

I understand that SDL.h or some other header redefines my 'main', as it wants to use its own main() routine. That presumably lives in some statically linked library of SDL, as it can't be inside SDL2.dll. I don't have that library and can't see any point in getting it as I won't be able to use it in my own language (also it will be implementation specific or even come as source code, in which case forget it!).

I managed to get a basic test program working by adding '#undef main'.

My question is, however, is there anything essential in SDL's main() that I will need, or that is likely to bite me in the future? Or can I get away without it? (And why doesn't SDL just depend on some SDL_init() routine for me to call from my main()?)

(I registered with SDL forums to ask about this, but apparently they don't allow me to post, as I don't have the right privileges. So what was the point of registering?!)

Instead of #undef main you should #define SDL_MAIN_HANDLED before including SDL.h (or define it via compiler flag).

If you implement custom main function you should at least call SDL_SetMainReady . For some platforms, SDL performs additional operations, like setting specific exception handlers, converting arguments to UTF8, or something completely different (eg for android it is not really a main but JNI function).

SDL's entry point defined in SDL2main library, don't really understand what you did to 'don't have it' (aside from manually deleting it). You can always download archive from libsdl.org or build it yourself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM