在使用SDL2库进行开发的时候,一开始会遇到标题所示的问题。
解决办法是自定义SDL_MAIN_HANDLED宏,如#define SDL_MAIN_HANDLED即可解决问题。
产生这个问题的原因是SDL把main函数变成了自己的SDL_main,详见SDL_main.h里,
#if defined(SDL_MAIN_NEEDED) || defined(SDL_MAIN_AVAILABLE)
#define main SDL_main
#endif
SDL_MAIN_NEEDED和SDL_MAIN_AVAILABLE默认是会开启其中一个的。详见SDL_main.h里,
#ifndef SDL_MAIN_HANDLED
#if defined(__WIN32__)
/* On Windows SDL provides WinMain(), which parses the command line and passes
the arguments to your main function.
If you provide your own WinMain(), you may define SDL_MAIN_HANDLED
*/
#define SDL_MAIN_AVAILABLE
#elif defined(__WINRT__)
/* On WinRT, SDL provides a main function that initializes CoreApplication,
creating an instance of IFrameworkView in the process.
Please note that #include'ing SDL_main.h is not enough to get a main()
function working. In non-XAML apps, the file,
src/main/winrt/SDL_WinRT_main_NonXAML.cpp, or a copy of it, must be compiled
into the app itself. In XAML apps, the function, SDL_WinRTRunApp must be
called, with a pointer to the Direct3D-hosted XAML control passed in.
*/
#define SDL_MAIN_NEEDED
#elif defined(__IPHONEOS__)
/* On iOS SDL provides a main function that creates an application delegate
and starts the iOS application run loop.
See src/video/uikit/SDL_uikitappdelegate.m for more details.
*/
#define SDL_MAIN_NEEDED
#elif defined(__ANDROID__)
/* On Android SDL provides a Java class in SDLActivity.java that is the
main activity entry point.
See README-android.md for more details on extending that class.
*/
#define SDL_MAIN_NEEDED
#elif defined(__NACL__)
/* On NACL we use ppapi_simple to set up the application helper code,
then wait for the first PSE_INSTANCE_DIDCHANGEVIEW event before
starting the user main function.
All user code is run in a separate thread by ppapi_simple, thus
allowing for blocking io to take place via nacl_io
*/
#define SDL_MAIN_NEEDED
#endif
#endif /* SDL_MAIN_HANDLED */
如果想要让这两个宏都不定义,那么最好的办法就是自己定义一个SDL_MAIN_HANDLED的宏,
意思就是自己有main函数,不需要sdl提供。