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的定义
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 2 本地部署DeepSeek模型构建本地知识库+联网搜索详细步骤