I am trying to setup SDL Library on a Windows Platform with VSCode. I used the official SDL Page to download SDL 2.0.12. I have followed Lazyfoo’s Tutorial to set up with MinGW. Here’s what I’ve done :
-
Created a “mingw_dev_lib” Folder in my C drive
-
Extracted the contents of “i686-w64-mingw32” into “mingw_dev_lib”.
-
Then made a Source file for testing setup
#include <iostream> #include <SDL2/SDL.h> int main(int argc, char * argv[]) { // Initialize SDL with video SDL_Init(SDL_INIT_VIDEO); // Create a window with SDL if(SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF | SDL_OPENGL) == 0) { std::cerr << "Failed to set video mode\n"; return 1; } SDL_Event event; // used to store any events from the OS bool running = true; // used to determine if we're running the game while(running) { // poll for events from SDL while(SDL_PollEvent(&event)) { // determine if the user still wants to have the window open // (this basically checks if the user has pressed 'X') running = event.type != SDL_QUIT; } // Swap OpenGL buffers SDL_GL_SwapBuffers(); } // Quit SDL SDL_Quit(); return 0; }
I use this command in my terminal:
g++ 01_hello_SDL.cpp -IC:\mingw_dev_lib\include\SDL2 -LC:\mingw_dev_lib\lib -w -Wl,-subsystem,windows -lmingw32 -lSDL2main -lSDL2 -o 01_hello_SDL
Errors
01_hello_SDL.cpp: In function ‘int SDL_main(int, char**)’:
01_hello_SDL.cpp:11:36: error: ‘SDL_DOUBLEBUF’ was not declared in this scope
11 | if(SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF | SDL_OPENGL) == 0)
| ^~~~~~~~~~~~~
01_hello_SDL.cpp:11:52: error: ‘SDL_OPENGL’ was not declared in this scope
11 | if(SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF | SDL_OPENGL) == 0)
| ^~~~~~~~~~
01_hello_SDL.cpp:11:5: error: ‘SDL_SetVideoMode’ was not declared in this scope; did you mean ‘SDL_ScaleMode’?
11 | if(SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF | SDL_OPENGL) == 0)
| ^~~~~~~~~~~~~~~~
| SDL_ScaleMode
01_hello_SDL.cpp:32:3: error: ‘SDL_GL_SwapBuffers’ was not declared in this scope
32 | SDL_GL_SwapBuffers();
| ^~~~~~~~~~~~~~~~~~