I am writing a C++ program in VSCode. However, when I press F5, all it does is build the project. I tried making another simple project in VSCode to see if it works, but no luck. Here is my mini-program
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;
}
I have tried reinstalling VSCode with no luck. When I try to debug a python script, it works just fine, so the problem is only with C++. How do I debug this debugging error?
CLARIFICATION: I am not getting an error from the debugger. Instead, the debugger for C++ isn’t launching at all.
2
Answers
Because you are missing the debugger’s path in your
launch.json
. Add a path to the debugger within themiDebuggerPath
.Or, you can use the Add Configuration button (visible in
launch.json
) to set up a new debugging configuration.You can do following steps and see if it works:
do share your results..