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

萝らか妹 提交于 2019-12-25 04:59:13

问题


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?


回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!