VS Code c_cpp_configuration.json includePath with ** for kernel headers doesn't work

98 views Asked by At

While developing a Linux kernel module in VS Code, I stumbled upon an interesting behaviour.

With this c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/src/linux-headers-5.15.0-91-generic/arch/x86/include",
                "/usr/src/linux-headers-5.15.0-91-generic/arch/x86/include/generated",
                "/usr/src/linux-headers-5.15.0-91-generic/include",
                "/usr/src/linux-headers-5.15.0-91-generic/arch/x86/include/uapi",
                "/usr/src/linux-headers-5.15.0-91-generic/arch/x86/include/generated/uapi",
                "/usr/src/linux-headers-5.15.0-91-generic/include/uapi",
                "/usr/src/linux-headers-5.15.0-91-generic/include/generated/uapi",
                "/usr/src/linux-headers-5.15.0-91-generic/ubuntu/include",
                "/usr/lib/gcc/x86_64-linux-gnu/9/include"
            ],
            "defines": [
                "__GNUC__",
                "__KERNEL__"
            ],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

everything works fine: all #include <linux/...> get resolved properly.

With this c_cpp_properties.json:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/src/linux-headers-5.15.0-91-generic/**",
                "/usr/lib/gcc/x86_64-linux-gnu/9/include"
            ],
            "defines": [
                "__GNUC__",
                "__KERNEL__"
            ],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c17",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

I get errors saying basically that almost all if not all of my kernel-specific structs, functions and macros are undefined.

Why is that? The second config is supposed to be containing all the paths from the first one.

1

There are 1 answers

0
starball On

I think I can reproduce this (not sure if exactly the same cause). I can't speak for why, but I think I found workarounds:

I can get recursiveness by using /.../**/* instead of /.../**.

Though that's a bit... heavy and messy. Unless you really want total recursiveness, might I suggest instead doing something like this?

"/usr/src/linux-headers-<version>-generic/**/include",
"/usr/src/linux-headers-<version>-generic/**/include/generated",
"/usr/src/linux-headers-<version>-generic/**/include/uapi",
"/usr/src/linux-headers-<version>-generic/**/include/generated/uapi",