Vscode-cpptools: Debug error "Unable to '...': File not Found"

Created on 12 Feb 2018  路  6Comments  路  Source: microsoft/vscode-cpptools

  • Windows 10
  • VS Code version 1.20.0
  • C/C++ extension version 0.14.6
  • Other extensions: C++ Intellisense

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}"
            ]
        }
    ]
}
debugger

Most helpful comment

Thank you for your answer.
I set sourceFileMap path like this:

"sourceFileMap": {
    "/c/": "C:/"
}

Now it works fine :)

All 6 comments

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

  1. c_cpp_properties.json
    "compilerPath": "C:/MinGW/bin/g++.exe"
  2. launch.json
    "miDebuggerPath": "C:/MinGW/bin/gdb.exe"
  3. tasks.json
    "command": "C:/MinGW/bin/g++.exe"

This will resolve your compiling and debugging problem in windows.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thndrwrks picture thndrwrks  路  3Comments

vicatcu picture vicatcu  路  3Comments

SkyRiderMike picture SkyRiderMike  路  3Comments

jheinzel picture jheinzel  路  3Comments

ismadelgad11 picture ismadelgad11  路  3Comments