SDL Error Undefined symbols for architecture x86_64 “_SDL_main”

后端 未结 2 1416
小鲜肉
小鲜肉 2021-02-14 07:03

I am using C++ with the SDL Cocoa and Foundation framework on my mac os x. I get the following error

Undefined symbols for architecture x86_64:
  \"_SDL_main\",         


        
2条回答
  •  伪装坚强ぢ
    2021-02-14 07:23

    I bet your main function signature is incorrect. You use:

    int main(int argc, const char * argv[])
                       ^^^^^
    

    but SDL_main.h wants

    int main(int argc, char *argv[])
    

    Why?

    You see, SDL does something really horrific when compiling: It renames your main function to SDL_main, injecting its own main function which, in turn, calls yours.

    Note that if this doesn't work, then you may be compiling with wrong flags. To be sure, get the flags by typing:

    $ sdl-config --cflags --libs
    

    For more information, see Simply including SDL header causes linker error

提交回复
热议问题