c++visual-studiovisual-c++sdlsdl-2

Cannot open source file "SDL2/SDL.h" Microsoft Visual Studio


I installed SDL2 and set up all the include and library directories in Microsoft Visual Studio. I also added the .lib files to the linker.

However, when I try to compile:

#include <SDL2/SDL.h>

I get the error:

Cannot open source file "SDL2/SDL.h"

I’m not sure what I’m missing. I’ve double-checked that SDL2 is installed and all the paths are set correctly in Visual Studio, but I still get the same error. How can I fix this?


Solution

  • I figured it out.

    The problem was that I used:

    #include <SDL2/SDL.h>
    

    This tells the compiler to look for a folder named SDL2 inside the include directory, but in my setup, the SDL.h file was placed directly in the include directory, not inside an SDL2 subfolder.

    So all I needed to do was remove the SDL2/ part and just write:

    #include <SDL.h>
    

    After that, everything compiled fine.