I tried to debug C++ file with gdb, but following error message is appeared.
Unable to 'main.cpp': File not found (file:///c/Users/.../main.cpp)
But I set the program path in launch.json file like this:
"program": "C:/Users/.../main.exe"
I think it's because VS Code recognizes C: to c, but I couldn't find any solutions to fix this issue.
How can I set target program's path correctly?
This is my tasks.json file:
{
"version": "2.0.0",
"runner": "terminal",
"type": "shell",
"echoCommand": true,
"presentation": { "reveal": "always" },
"tasks": [
{
"label": "Save & Compile C++",
"command": "g++",
"args": [
"${file}",
"-g", "-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"group": "build",
"problemMatcher": {
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
},
{
"label": "execute",
"command": "cmd",
"group": "test",
"args": [
"/C", "${fileDirname}\\${fileBasenameNoExtension}"
]
}
]
}
I think this is how it is compiled. You can try specifying "sourceFileMap" in your launch.json to have it map from upper to lowercase. I assume that error is a VS Code error that it can't find the file which is displayed as a drop down message at the top?
@pieandcakes How can I specify sourceFileMap?
@Luberen The documentation is at the bottom of this article.
I think your format will be:
```
"sourceFileMap": {
"c:\": "C:\"
}
Thank you for your answer.
I set sourceFileMap path like this:
"sourceFileMap": {
"/c/": "C:/"
}
Now it works fine :)
Im not getting output.. I just tried C++ hello world..
Im getting debug console
"You may only use the C/C++ Extension for Visual Studio Code with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications."
I installed C/C++ extension. when I tried to debug using GDB it shows path error
please help me to solve this.
Windows :
Please make sure if you have gdb.exe in your bin folder
C:MinGWbingdb.exe
if not then you can directly install the gdb.exe by following commands -
In command prompt browsed to C:MinGWbin and run : mingw-get.exe to install gdb
C:MinGWbin>mingw-get.exe install gdb
After that modify your path in three files in vs code
This will resolve your compiling and debugging problem in windows.
Most helpful comment
Thank you for your answer.
I set
sourceFileMappath like this:Now it works fine :)