error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup, but this time it's NOT a Windows/Console problem!

后端 未结 4 1521
礼貌的吻别
礼貌的吻别 2020-12-13 10:22

So, the infamous error is back. The project is complaining that it can\'t find the main() method (that\'s what the error means, right).

However I do have a main, and

相关标签:
4条回答
  • 2020-12-13 10:27

    Another option would actually to define your own main with the usual parameters

    int main(int argc, char *args[])
    {
        // Your code here
    }
    

    That should get rid of the error.

    Then if you don't use those parameters and you also want to get rid of the compiler warning you could do that trick in your main function.

    (void)argc;
    (void)args;
    
    0 讨论(0)
  • 2020-12-13 10:27

    The default solution from SDL documentation:

    tl;dr:

    #define SDL_MAIN_HANDLED
    #include "SDL.h"
    

    full example:

    Use this function to circumvent failure of SDL_Init() when not using SDL_main() as an entry point.

    #define SDL_MAIN_HANDLED
    #include "SDL.h"
    
    int main(int argc, char *argv[])
    {
        SDL_SetMainReady();
        SDL_Init(SDL_INIT_VIDEO);
    
        ...
    
        SDL_Quit();
    
        return 0;
    }
    

    Source: https://wiki.libsdl.org/SDL_SetMainReady

    0 讨论(0)
  • 2020-12-13 10:29

    SDL_main.h is included automatically from SDL.h, so you always get the nasty #define.

    Just write:

    #include <SDL.h>
    #undef main
    

    And it should work fine

    0 讨论(0)
  • 2020-12-13 10:40

    The culprit is likely to be SDL_main.h. Check that you don't include that file, there is a nasty define there:

    #define main SDL_main
    
    0 讨论(0)
提交回复
热议问题