view raw
Jimmy_Rustle Jimmy_Rustle - 9 months ago 84
C Question

Linker Error when using the SDL Library: _main already defined in main.obj

So I already know why this error happens, inside the SDL_main.h file a 'main' macro is being created, which will cause problems with your actual main function.

It's just that none of the obvious workarounds seem to be helping me. I have tried:

  1. Defining my main function with (int argc, char* argv[]).

  2. Tried it with C linkage like the comments in SDL_main.h suggest:

    * The application's main() function must be called with C linkage,
    * and should be declared like this:
    * \code
    * #ifdef __cplusplus
    * extern "C"
    * #endif
    * int main(int argc, char *argv[])
    * {
    * }
    * \endcode

  3. Tried undefining main.

Are there any other tricks I can try in order to get the main function working normally again?


Try also this at the top of your main.cpp file:


That is supposed to cause SDL to skip all of its main nonsense.

Note that it needs to happen before you include SDL:

#include "SDL2/SDL.h"