Undefined reference to 'SDL_main' while using Dev C++

为君一笑 提交于 2019-12-02 01:32:51

This error is common when using int main() instead of :

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

Try replacing it with either of these.

In the background, SDL defines a macro #define main SDL_main that renames your main(int argc, char *argv[]) function so that it does not conflict with its own main() function (used for SDL initialization). If you use main() instead, the macro does not modify it and SDL_main is then not found.

If it does not work, follow these steps:

  • When you create your project, make sure you choose a Win32 GUI or Win32 Console application type.

  • After creating your project, I assume you added the following command line to your project parameters under linker : -lmingw32 - -lSD2main -lSDL2

  • Then put SDL2.dll in your project directory where your executable will be.

  • Include SDL2.h before main(int argc, char **argv) begins in your source code.

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