so I want to debug my .cpp program file but when I click on the Run and Debug button and proceed to select my debugging environment (C (GDB/LLDB)), the popup to select the configuration option does not even appear at all and the debugging just doesn't start.
This is before I click the environment popup:
Any help I can get for this problem is greatly appreciated as I can't seem to find any solutions at all on the internet, thank you very much!
p.s I've already tried uninstalling VS Code completely off my laptop and resetted all the settings and it didn't work.
CodePudding user response:
Are you sure you installed the C/C Studio Code extension? If you don't get the popup, try writing the json files manually.
Create a .vscode
folder in your working directory. In there create a file launch.json
in which you declare how you run the debugger
{
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}\\test.exe",
"stopAtEntry": true,
"cwd": "${workspaceRoot}",
"preLaunchTask": "Build Debug",
"miDebuggerPath": "c:\\mingw64\\bin\\gdb.exe"
}
]
}
This runs the gdb
debugger that came with MinGW. You need to provide the path to your debugger at miDebuggerPath
.
This debugs an executable test.exe
that needs to be created in debug mode. For this you have the preLaunchTask
option. In .vscode
create a file tasks.json
in which you describe the debug task as
{
"tasks": [
{
"type": "cppbuild",
"label": "Build Debug",
"command": "g ",
"args": [
"${workspaceRoot}\\test.cpp",
"-g",
"-o",
"${workspaceRoot}\\test.exe"
],
}
],
"version": "2.0.0"
}
This uses the gcc
or g
compiler that also comes with MinGW to compile a single source file test.cpp
into the test.exe
binary. You can select the debug launch configuration in the lower left corner of Studio Code and click Run.