使用预编译头文件时,使用 vscode 在智能感知中自动包含头文件

Automatically include header files in intellisense with vscode when using precompiled header

我在 macOS 10.15 上,我正在为一个项目使用 vscode。对于这个项目,我设置了预编译头文件。编译运行良好,但预编译头文件不包含在我的文件中。相反,它们包含在编译器选项 -include pch.hpp 中(如 here 所述)。问题是因为我的文件中没有包含这些内容,所以 IntelliSense 无法正常工作并且我有很多包含错误。在 c_cpp_properties.json 中,我尝试添加行

"compilerArgs": [
"-include ${workspaceFolder}/emulator/pch.hpp"
]

但是没有用,错误仍然存​​在。有没有办法告诉 IntelliSense 自动包含文件?

我之前做的是

#ifndef BUILD
   #include "pch.hpp"
#endif

在我所有其他文件中包含的 util.hpp 文件中,并在编译时使用 -DBUILD 定义 BUILD。问题是每当我修改我的 util.hpp 文件时,我都必须重新创建我的预编译头文件,因为 clang 告诉我我的 util.hpp 文件比预编译头文件更新。

使用forcedInclude, c_cpp_properties.json:

"configurations": [
    {
       ...
       "forcedInclude": ["${workspaceFolder}/include/config.h"],
       ...
    }
]