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

Viewed 1169

I'm developing on Win10 a C++ programm for Webassembly.

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

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

Emscripten itself creates correctly the .wasm file. But Intellisense in Visual Studio Code shows always the source of #include <SDL2/SDL.h> can't be found. My c_cpp_properties.json looks like this:

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

I can't find the directory SDL2 under ...\\emsdk-master\\upstream\\emscripten\\system\\". What I'm doing wrong?

1 Answers

Assuming you're using the Emscripten Ports version of SDL2 (via -s USE_SDL=2), you need to add the Emscripten Ports installed include directory to your "includePath".

Typically it is located at .emscripten_cache/wasm-obj/include in your user profile (e.g. C:\Users\PowerNow\.emscripten_cache\wasm-obj\include).

This directory may only exist after the first time your run emcc or em++ with the -s USE_SDL=2 option (or equivalent option for other Ports).

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