• Download MSYS2 from here
  • Insert the following command to install the mingw64 toolchain and SDL2
pacman -S mingw-w64-ucrt-x86_64-toolchain
pacman -S mingw-w64-x86_64-SDL2
  • All the libraries and toolchain components, including SDL2 will be found in C:/msys64/mingw64
  • Go to VS Code and look for 2 files, c_cpp_properties.json and tasks.json. If they are not there, use Ctrl + Shift + P and select “C/C++: Edit Configurations (JSON)” and “Tasks: Configure Default Build Task”
  • My code in c_cpp_properties.json looks like this
{
    "configurations": [
        {
            "name": "windows-gcc-x64",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\msys64\\mingw64\\include\\SDL2\\"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.22000.0",
            "compilerPath": "C:\\msys64\\mingw64\\bin\\g++.exe",
            "cStandard": "${default}",
            "cppStandard": "${default}",
            "intelliSenseMode": "windows-gcc-x64"
        }
    ],
    "version": 4
}
  • My code in tasks.json looks like this
{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\msys64\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe",
                "-I",
                "C:\\msys64\\mingw64\\include\\SDL2\\",
                "-L",
                "C:\\msys64\\mingw64\\lib\\",
                "-lSDL2",
                "-lSDL2main"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

This should all sort any issues related to being unable to detect the SDL2 headers and libraries