使用clang编译,codelldb扩展调试搭建c/c++环境
step1
sudo apt update
sudo apt upgrade
sudo apt install llvm lldb clang
step2
Visual Studio Code - Code Editing. Redefinedhttps://code.visualstudio.com/
下载.deb 安装vscode
sudo dpkg -i xxx.deb
安装扩展
codelldb c/c++
step3
新建文件夹--vscode将文件夹添加到工作区---工作区另存为--新建.c文件
step4
配置编译任务
-
按
Ctrl+Shift+P
输入 Tasks: Configure Task,选择 Create tasks.json from template → Others。 -
{ "version": "2.0.0", "tasks": [ { "label": "Build with Clang", "type": "shell", "command": "clang", "args": [ "-g", // 生成调试信息 "${file}", // 当前文件 "-lm" //添加数学库链接 "-o", // 输出文件 "${fileDirname}/${fileBasenameNoExtension}" ], "group": { "kind": "build", "isDefault": true }, "problemMatcher": [] } ] }
step5
配置 launch.json
-
在项目目录下创建
.vscode/launch.json
(如果不存在)。 -
使用以下配置:
"version": "0.2.0", "configurations": [ { "name": "Debug with LLDB (CodeLLDB)", "type": "lldb", // 使用 CodeLLDB 扩展 "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": [], "cwd": "${workspaceFolder}", “console”: "externalTerminal", "preLaunchTask": "Build with Clang" // 确保与 tasks.json 的任务名匹配 } ] }
ctrl+f5运行
F5调试