[SDL] Undefined reference to SDL_main

Brian brian.ripoff at gmail.com
Sat Jan 19 08:48:26 PST 2008


extern "C" disables C++ name mangling. You don't need this because
SDL_main.h declares SDL_main for you, and you only need the extern "C"
in the declaration (I think).

What main looks like matters to SDL because SDL works on platforms,
such as windows, where the entry point might be different. In windows,
a non-console application has an entry point called WinMain().
SDL_main provides this for you, by #defining your main to SDL_main. So
really, the main() you write isn't main() at all, so you must conform
to SDL's SDL_main signature, which includes argc and argv. Likewise,
even though the C++ standard allows main() to not explicitly return a
value (in which case the implementation should make it return 0), your
SDL_main must return a value (if you have a high enough warning level
you'll see this).

> What is the  extern "C" for? I tried it without, and it worked.
> It seems that SDL likes it just fine when main is defined that way. No other
> changes. I'd really rather not just make that change without knowing why though.
> I don't want it to work, I want to understand it. Why does it matter what my
> main is? Explanations or pointers to such are much appreciated.


More information about the SDL mailing list