我正在用VSCode编写一个C++程序。但是,当我按下F5键时,它所做的只是构建项目。我尝试用VSCode创建另一个简单的项目,看看它是否能工作,但没有成功。下面是我的迷你程序
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;
}
我试着重新安装VSCode,但没有成功。当我试着调试python脚本时,它工作得很好,所以问题只出在C上。我该如何调试这个调试错误?澄清:我没有从调试器中得到错误。相反,C的调试器根本没有启动。
2条答案
按热度按时间kwvwclae1#
相反,C++调试器根本不启动。
因为
launch.json
中缺少调试器的路径。请在miDebuggerPath
中添加调试器的路径。或者,您可以使用“添加配置”按钮(在
launch.json
中可见)设置新的调试配置。qxsslcnc2#
您可以执行以下步骤,看看它是否工作:
请分享您的结果..