为什么VSCode的Intellisense无法解析#if定义__GNUC__?

问题描述

我使用Atom,CLion进行内核模块开发,我想尝试VSCode。

Intellisense找不到某些类型和宏,例如所有uint*_tu*dev_tDECLARE_BITMAP()

快速浏览types.h之后,似乎所有这些类型/宏都在#if defined(__GNUC__)之后定义。

这是我的@H_404_27@ c_cpp_properties.json :

{
    "configurations": [
        {
            "defines": [
                "__GNUC__","__KERNEL__","_GNU_SOURCE","MODULE",],"name": "Linux","includePath": [
                "${workspaceFolder}/**","/usr/src/kernels/3.10.0-1127.8.2.el7.x86_64/include/**","/usr/src/kernels/3.10.0-1127.8.2.el7.x86_64/arch/x86/include/**"
            ],"compilerPath": "/opt/rh/devtoolset-7/root/usr/bin/gcc","cStandard": "gnu11","cppStandard": "gnu++14","intelliSenseMode": "gcc-x64"
        }
    ],"version": 4
}

解决方法

Linux内核具有许多头文件,它们具有相同的名称,但是位于不同的目录中。这些文件的确切路径确实很重要。

因此,最好不要“使用glob”(使用终止符/**)来包含Linux内核的目录,而要写 exact

"includePath": [
    # You could glob include directories for your module
    "${workspaceFolder}/**",# .. but do not glob Linux kernel ones
    "/usr/src/kernels/3.10.0-1127.8.2.el7.x86_64/include",# Do not glob arch-specific include directories for Linux kernel too
    "/usr/src/kernels/3.10.0-1127.8.2.el7.x86_64/arch/x86/include"
],