VSCode IntelliSense 无法识别 SDL_image SDL 框架的扩展库

VSCode IntelliSense not recognising SDL_image extension library for SDL framework

我试图在我的项目中将 SDL_image 扩展库包含到 SDL.framework,但是 VScode 的 IntelliSense 一直在我的 #include<SDL_image.h> 下划线并显示错误行。它会产生以下错误:

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

我成功地编辑了 c_cpp_properties.json includePath,因此 IntelliSense 识别了 SDL 框架,但是当尝试用 SLD_image 做同样的事情时失败了。

这是我的 c_cpp_properties.json 文件:

{
    "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
}

问题不在于 c_cpp_properties.json,而在于 SDL_image.h 文件。如果您正在使用 VScode(尽管在 mac 上)并且遇到与 IntelliSense 相同的问题,请将 SDL_image.h 中的以下 include 语句更改为:

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

对此:

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

值得注意的是,我在 Windows 10 上遇到了完全相反的问题,只是将它们换成了另一种方式。

发件人:

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

收件人:

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

因为这是 .h 文件的确切路径