Undefined reference to 'SDL_main'

Try #undef main after all SDL related headers.

Update. This is not a valid solution!

As pointed out by HolyBlackCat, this is a pretty sloppy fix. SDL replaces the main function in order to perform some initialization and/or cleanup that is otherwise not possible, and then calls back to the actual user function.

The interception works by replacing the name of user's main function to SDL_main, with a simple macro

#define main SDL_main

The user's function then ceases to be the entry point for the application, and an entry point provided by SDL is used. The proposed #undef disables the interception recklessly and one should argue that it is not supposed to work at all. For those who successfully compiled and ran an SDL application after this "fix", it must have simply been a platform-dependent coincidence.

The proper solution to the OP's error is making sure that the file containing main gets compiled and linked, and that the function has correct signature. As already posted by others.


put these arguments to the main function. I had this problem too, and I fixed it few seconds ago.

int main(int argv, char** args) { }