Jimmy_Rustle
Jimmy_Rustle

Reputation: 329

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?

Upvotes: 1

Views: 3081

Answers (1)

Chris Beck
Chris Beck

Reputation: 16204

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

#define SDL_MAIN_HANDLED

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

Note that it needs to happen before you include SDL:

#define SDL_MAIN_HANDLED
#include "SDL2/SDL.h"

Upvotes: 3

Related Questions