When developing code in vs code, we may encounter the problem of "launch: program 'c: \build\Debug\outDebug' does not exist" during running or debugging, as shown in the figure.
Here we follow the prompts to open "launch.json"
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": true,
"cwd": "c:/Users/13967/Desktop/c/output",
"program": "c:/Users/13967/Desktop/c/output/build/Debug/outDebug/",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
After observation, I found that the problem should appear in the program
"program": "c:/Users/13967/Desktop/c/output/build/Debug/outDebug/",
The specific location of the code is located here, but this location is not accurate enough.
As shown in the picture, the compilation results of the C language code I wrote are stored in "C:\Users\13967\Desktop\c\output".
instead of "c:/Users/13967/Desktop/c/output/build/Debug/outDebug/" in "launch.json"
Therefore, we first need to change the file location to the folder where the C language compilation results are stored on our computer, and then add a line of "${fileBasenameNoExtension}.exe" at the end to locate the specific .exe application.
Taking my computer as an example, I finally changed it to this:
"program": "c:/Users/13967/Desktop/c/output/${fileBasenameNoExtension}.exe",
Problem solved successfully! As shown in the figure, the code can already set breakpoints and debug.
References: