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

前端 未结 1 1646
孤独总比滥情好
孤独总比滥情好 2021-01-21 14:04

i am currently having problem compiling my project in dev c++ which uses SDL libraries, what i did was first download the file SDL2-devel-2.0.3-mingw.tar.gz (MinGW

1条回答
  •  抹茶落季
    2021-01-21 14:36

    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.

    0 讨论(0)
提交回复
热议问题