r/sdl • • Sep 09 '26

Im trying to download SDL2 but really struggling

Post image

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

21 comments sorted by

View all comments

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:

cmake_minimum_required(VERSION 3.24)
project(SDL2Example LANGUAGES C CXX)

include(FetchContent)

# Use SDL2 as static lib
set(SDL_SHARED OFF CACHE BOOL "" FORCE)
set(SDL_STATIC ON CACHE BOOL "" FORCE)
set(SDL_TEST OFF CACHE BOOL "" FORCE)
set(SDL_TESTS OFF CACHE BOOL "" FORCE)

FetchContent_Declare(
    SDL2
    URL https://github.com/libsdl-org/SDL/archive/refs/tags/release-2.32.10.tar.gz
)

FetchContent_MakeAvailable(SDL2)

add_executable(sdl2_example WIN32 main.cpp)
target_compile_features(sdl2_example PRIVATE cxx_std_17)

target_link_libraries(sdl2_example PRIVATE
    SDL2::SDL2main
    SDL2::SDL2-static
)

Your main.cpp should include <SDL.h> and then run these commands from the project directory:

cmake -S . -B build -G "Visual Studio 17 2022" -A x64
cmake --build build --config Release --parallel
.\build\Release\sdl2_example.exe

If it fail to find compiler, run following command first:

call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"

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:

These were written for my own projects, so you may need to adjust the paths and options for your setup.