linux源码阅读配置 vscode+clangd
以我的linux学习仓为例
准备工作
vscode需要安装clangd插件
sudo apt-get install clangd-15
快速使用: 这是我已经编译好compile_commands.json的仓库
git clone https://gitee.com/rongbaichuan/linux-learn.git
编译
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
make mrproper
make CC=clang defconfig
make CC=clang -j16
python3 ./scripts/clang-tools/gen_compile_commands.py
# 之后会在源码根目录下生成compile_commands.json
workspace目录没有compile_commands.json的话, 创建一个软链接指向子目录中的compile_commands.json
setting.json
在 setting.json 添加下面的配置
{
"folders": [
{
"path": "."
}
],
"settings": {
"C_Cpp.default.intelliSenseMode": "linux-gcc-arm64",
"C_Cpp.intelliSenseEngine": "disabled",
"clangd.path": "/usr/bin/clangd-15",
"clangd.arguments": [
"--compile-commands-dir=${workspaceFolder}",
"--background-index",
"--completion-style=detailed",
"--header-insertion=never",
"--log=info",
"--pretty"
],
"workbench.colorCustomizations": {
//设置用户选中代码段的颜色
"editor.selectionBackground": "#c80000",
"editor.selectionHighlightBorder": "#ff1100",
//设置活动tab窗口颜色
"tab.activeBackground": "#008e0c9a"
},
"editor.detectIndentation": false,
//vscode设置的缩进量
"editor.tabSize": 8,
//保存时候自动格式化,不建议设置。我在这里设置为false
"editor.formatOnSave": false,
"files.associations": {
"*.h": "c",
"*.md": "c",
},
"files.autoSave": "afterDelay",
"editor.renderWhitespace": "all",
"editor.minimap.enabled": false,
}
}
reload
vscode安装Clangd插件, reload window, 就会开始索引 compile_commands.json
测试
自动跳转到arm64的定义



浙公网安备 33010602011771号