核心插件
注意:最好禁用 IntelliCode 以免和 clangd 冲突。
生成 compile_commands.json
cmake 配置项目时添加 -DCMAKE_EXPORT_COMPILE_COMMANDS=1,或者直接在 CMakeLists.txt 中添加:
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
这一步是为了生成 compile_commands.json。
之后在 cmake 配置后 clangd 便可正常工作。
配置 c_cpp_properties.json
配置 .vscode/c_cpp_properties.json, 添加 “compileCommands”: ”${workspaceFolder}/build/compile_commands.json”, 示例如下:
{
"configurations": [
{
"name": "Linux",
"compilerPath": "/usr/bin/g++",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "${default}",
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}