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

new9mtju  于 11个月前  发布在  Linux
关注(0)|答案(1)|浏览(110)

在用VS Code开发Linux内核模块时,我偶然发现了一个有趣的行为。
关于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
}

字符串
一切正常:所有#include <linux/...>都得到正确解决。
关于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
}


我得到的错误基本上说,几乎所有的,如果不是所有的内核特定的结构,函数和宏是未定义的。

**为什么?**第二个配置应该包含第一个配置的所有路径。

fgw7neuy

fgw7neuy1#

我想我可以重现这一点(不确定是否完全相同的原因)。我不能说为什么,但我想我找到了解决办法:
我可以通过使用/.../**/*而不是/.../**来获得递归性。
虽然这有点......沉重和混乱。除非你真的想要完全递归,我可以建议你这样做吗?

"/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",

字符串

相关问题