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
post the compiler commands. ex: g++/gcc ....
you are probably not linking the library.
http://content.gpwiki.org/index.php/SDL:Tutorials:Setup you should have the path to the lib, included in the ide. (I see you are using codeblocks)
add to the linker settings: -lmingw32 -lSDLmain -lSDL
http://www.sdltutorials.com/sdl-tutorial-basics
I think you want
#define SDL_MAIN_HANDLED
in your main file, BEFORE the line
#include <SDL2/SDL.h>
from: https://stackoverflow.com/a/32343111/5214543
Although the accepted answer works (if you follow it exactly, or read the comments), there's one caveat: You have to follow the order of linking libraries as given
g++ 01_hello_SDL.cpp -I{add correct path here}/include/SDL2 -L{add correct path here}/lib -lmingw32 -lSDL2main -lSDL2
And if you dont want a console to run alongside the window, add -mwindows
to the options
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 .
You need to add these to linker libraries with the same order:
mingw32
SDL2main
SDL2
Note that the order is important.
I solved this by exchanging the
int main(int argc, char* argv[])
line with
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
No idea why to be honest, then again I moved on to the SFML.