SDL 2 Undefined Reference to “WinMain@16” and several SDL functions

后端 未结 7 1009
一整个雨季
一整个雨季 2020-12-06 19:41

I\'ve just installed SDL 2 and I have some serious problems. This is my code:

#include 

int main(int argc, char* argv[]){
SDL_Init( SDL_I         


        
7条回答
  •  有刺的猬
    2020-12-06 20:16

    I just had a similar issue when trying to build and run a project in Eclipse CDT 1909 on Windows 10 that I had originally created in Eclipse on MacOS.

    I found the following steps worked using the minGW64 Compiler.

    RMB Click on the project and choose properties. In Project Properties > C/C++ Build create a new C/C++ Build Configuration by LMB Clicking Manage Configurations and LMB Clicking New, name it Debug_Windows, set Copy Setting from to Default configuration, make it active, LMB Click OK, set the Configuration to Debug_Windows.

    Set the Project Properties > C/C++ Build > Builder Settings > Build Command > Current Builder to CDT Internal Builder

    Set the Project Properties > C/C++ Build > Builder Settings > Tool Chain Editor > Current toolchain to MinGW GCC

    Set the Project Properties > C/C++ Build > Builder Settings > Tool Chain Editor > Current builder to CDT Internal Builder

    Add the following path to the Project Properties > C/C++ Build > Settings > GCC C++ Compiler > Includes "C:\Applications\Library\SDL2-2.0.9\x86_64-w64-mingw32\include\SDL2"

    Add the following path to Project Properties > C/C++ Build > Settings > GCC C++ Linker > Libraries "C:\Applications\Library\SDL2-2.0.9\x86_64-w64-mingw32\lib"

    add the following libraries to Project Properties > C/C++ Build > Settings > GCC C++ Linker > Libraries, in the order SLD2main SDL

    Navigate to Project Properties > Run/Debug Settings, LMB Click New, select C/C++ Application, LMB Click OK, in the C/C++ Application field enter Debug_Windows\project_name.exe (replacing project_name with the correct value).

    Change the Build Configuration to Debug_Windows.

    Close the project properties.

    Add the preprocessor directive #define SDL_MAIN_HANDLED at the top of the file containing the main function. Without the preprocessor directive the program will not link correctly.

    To run the program RMB Click on the project and choose Run as > Run Configurations and choose the run configuration created for the build.

    Copy SDL2.dll to the top level of the project directory structure, as if it is copied to the Debug or Debug_Windows directory it is deleted every time the project is built.

    The key points that I found were that it is not necessary to include mingw32 in the Linker Libraries and #define SDL_MAIN_HANDLED needs to be in the file containing main and before #include .

提交回复
热议问题