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

问题描述

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

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

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

  • 这是一个已知问题吗?
  • 如何解决?内核头文件充满了#if defined()

这是我的 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"
],

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...