VSCode中C++调试器无法启动,按下F5仅执行编译如何解决?
C++调试器在VSCode中无法启动(仅编译成功)的排查方案
问题描述
在VSCode中编写C++程序,按下F5键时仅完成项目编译,调试器完全无法启动。尝试新建简易项目、重装VSCode均未解决问题,但调试Python脚本可正常运行。
项目配置及代码
launch.json
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "C/C++: clang++ build and debug active file", "type": "cppdbg", "request": "launch", "program": "${fileDirname}/${fileBasenameNoExtension}", "args": [], "stopAtEntry": true, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "MIMode": "lldb", "preLaunchTask": "C/C++: clang++ build active file" } ] }
tasks.json
{ "tasks": [ { "type": "cppbuild", "label": "C/C++: clang++ build active file", "command": "/usr/bin/clang++", "args": [ "-fcolor-diagnostics", "-fansi-escape-codes", "-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}" ], "options": { "cwd": "${fileDirname}" }, "problemMatcher": [ "$gcc" ], "group": { "kind": "build", "isDefault": true }, "detail": "Task generated by Debugger." } ], "version": "2.0.0" }
main.cpp
#include <iostream> int main() { int sum = 0; for (int i = 0; i < 100; i++) { sum += i; std::cout<<"Sum: " << sum << std::endl; } return 0; }
排查解决步骤
检查LLDB调试器安装状态
终端执行lldb --version,确认能输出正常版本信息。若提示命令不存在,通过系统包管理器安装LLDB(如Linux下sudo apt install lldb)。验证可执行文件有效性
编译完成后,到对应目录执行./生成的可执行文件名,确认程序能正常运行;同时用ls -l 可执行文件名检查权限,确保有执行权限(权限位含x),无权限则执行chmod +x 可执行文件名添加。调整launch.json调试配置
- 将
externalConsole改为true,尝试唤起外部终端启动调试; - 添加
miDebuggerPath字段指定LLDB路径,比如:
可通过"miDebuggerPath": "/usr/bin/lldb-mi"which lldb-mi查询实际路径。
- 将
查看VSCode调试日志
打开输出面板(Ctrl+Shift+U),切换到"Debug Console"和"Log (Debug)"选项卡,排查是否有隐藏的权限、路径类报错。切换调试器模式测试
若为Linux系统,可将launch.json中MIMode改为gdb,安装GDB后,把tasks.json的编译命令改为g++,重新测试调试是否能启动,排除LLDB相关问题。更新C/C++扩展
打开VSCode扩展面板,找到"Microsoft C/C++"扩展,更新至最新版本后重启VSCode重试。
内容的提问来源于stack exchange,提问作者Aaryan
相关产品推荐
相关产品推荐

