Search code examples
c++jsonvisual-studio-codesdl

VSCode IntelliSense not recognising SDL_image extension library for SDL framework


I am trying to include the SDL_image extension library to SDL.framework in my project but VScode's IntelliSense keeps underlining my #include<SDL_image.h> with error lines. It produces the following error:

cannot open source file "SDL2/SDL.h" (dependency of "SDL_image.h")

I was successfully able to edit the c_cpp_properties.json includePath so IntelliSense recognised the SDL framework, but when trying to do the same thing with SLD_image it failed.

This is my c_cpp_properties.json file:

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "/Library/Frameworks/SDL2_image.framework/Headers",
                "/Library/Frameworks/SDL2.framework/Headers",
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

Solution

  • The problem wasn't with the c_cpp_properties.json but the SDL_image.h file. If you are using VScode (despite being on a mac) and encountering the same issue with IntelliSense, change the following include statements inside SDL_image.h from this:

    #include <SDL2/SDL.h>
    #include <SDL2/SDL_version.h>
    #include <SDL2/begin_code.h>
    #include <SDL2/close_code.h>
    

    to this:

    #include <SDL.h>
    #include <SDL_version.h>
    #include <begin_code.h>
    #include <close_code.h>