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的定义

posted @   容景云  阅读(20)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 2 本地部署DeepSeek模型构建本地知识库+联网搜索详细步骤
点击右上角即可分享
微信分享提示