问题
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:
Defining my main function with (int argc, char* argv[]).
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
Tried undefining main.
Are there any other tricks I can try in order to get the main function working normally again?
回答1:
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"
来源:https://stackoverflow.com/questions/38803379/linker-error-when-using-the-sdl-library-main-already-defined-in-main-obj