为什么使用 Emscripten 的 Intellisense 找不到 SDL2/SDL.h 的包含路径?

Why does Intellisense with Emscripten does not find the include path of SDL2/SDL.h?

我正在 Win10 上开发一个用于 Webassembly 的 C++ 程序。

#include <SDL2/SDL.h>
#include <stdlib.h>
#include <emscripten.h>

int main() {
    printf("Hello World!");
}

Emscripten 自己正确地创建了 .wasm 文件。但是 Visual Studio 代码中的 Intellisense 总是显示 the source of #include <SDL2/SDL.h> 找不到。我的 c_cpp_properties.json 看起来像这样:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "E:\PROGRAMS\emsdk-master\upstream\emscripten\system\**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "E:\PROGRAMS\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin\gcc.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

我在...\emsdk-master\upstream\emscripten\system\"下找不到目录SDL2。我做错了什么?

假设您使用的是 Emscripten Ports 版本的 SDL2(通过 -s USE_SDL=2),您需要将安装的 Emscripten Ports 包含目录添加到 "includePath".

通常它位于您的用户个人资料中的 .emscripten_cache/wasm-obj/include(例如 C:\Users\PowerNow\.emscripten_cache\wasm-obj\include)。

此目录可能仅在您第一次使用 -s USE_SDL=2 选项(或其他端口的等效选项)运行 emccem++ 后存在。

"includePath": [
    "${workspaceFolder}/**",
    "E:\PROGRAMS\emsdk-master\upstream\emscripten\system\**",
    "C:\Users\PowerNow\.emscripten_cache\wasm-obj\include"
],