vscode中clangd添加include path

Huan Lee Lv5

在做c++项目时, 常常需要额外添加include path, 如项目目录, include文件夹. 在编译时, 要么加到CMakeLists.txt中, 要么加-I/inlcude/path, 但是在编辑器中, 如何添加呢? 本文主要解决vscode环境下添加include path.

vscode 官方c++插件

官方的C++插件用的很多, 所以这个解决方案一搜就能搜到. 当然是要在根目录下添加一个c_cpp_properties.json, 然后在includePath属性中添加目标目录.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}",
"${workspaceFolder}/include"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "linux-clang-x64"
}
],
"version": 4
}

clangd 插件

clangd对那些用vim的c++开发者来说应该不陌生, 但是vscode中用的相对较少. 但就我个人体验来说, clangd相当不错, 尤其是在响应速度上超出官方插件许多. 只是由于相对小众, 相关的配置比较难找, 我个人也是废了一些力气, 才试出有效的方案. clangd添加include path也是修改settings.json

1
2
3
4
"clangd.fallbackFlags": [
"-I${workspaceFolder}/include",
"-I${workspaceFolder}"
]
  • Title: vscode中clangd添加include path
  • Author: Huan Lee
  • Created at : 2023-09-07 20:00:00
  • Updated at : 2024-02-26 04:53:15
  • Link: https://www.mirthfullee.com/2023/09/07/vscode中clangd添加include path/
  • License: This work is licensed under CC BY-NC-SA 4.0.
On this page
vscode中clangd添加include path