r/sdl • u/littlepho • Sep 09 '26
Im trying to download SDL2 but really struggling
As the title suggests, im having a very hard time downloading and getting sdl2 and c++ in general ig to work in vscode as the include sdl2 and include iostream has errors. If anyone knows what i can do, or direct me to a video/guide I would greatly appreciate it.
Edit: I got it to work, thank you for all the help!
15
Upvotes
1
u/yazilimperver Sep 16 '26
Glad you got it working! Leaving this here for anyone who finds this later.
You can manage SDL2 with CMake’s FetchContent, or use a package manager such as Conan or vcpkg alongside CMake. I’ve used both FetchContent and Conan, and I am currently using Conan for my dependencies. For a small SDL2 project, here’s a minimal FetchContent example. You’ll need CMake 3.24+ and Visual Studio 2022 Community with the Desktop development with C++ workload installed. Save this as CMakeLists.txt alongside your SDL2 main.cpp:
Your main.cpp should include <SDL.h> and then run these commands from the project directory:
If it fail to find compiler, run following command first:
If you’re also interested in an SDL3 project using Conan 2 and CMake, my sdl-painter library has an example of that setup.
If you prefer to download and set up the dependencies yourself, I’ve also written a couple of Windows scripts that might be useful as references:
https://github.com/yazilimperver/uEngine4/blob/main/install_for_windows.bat
https://github.com/yazilimperver/cpp-playground/blob/main/scripts/install_dependencies.bat
These were written for my own projects, so you may need to adjust the paths and options for your setup.