Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug error "Unable to '...': File not Found" #1546

Closed
DemoCrazer opened this issue Feb 12, 2018 · 10 comments
Closed

Debug error "Unable to '...': File not Found" #1546

DemoCrazer opened this issue Feb 12, 2018 · 10 comments
Labels

Comments

@DemoCrazer
Copy link

DemoCrazer commented Feb 12, 2018

  • 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}"
            ]
        }
    ]
}
@pieandcakes
Copy link
Contributor

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?

@DemoCrazer
Copy link
Author

@pieandcakes How can I specify sourceFileMap?

@pieandcakes
Copy link
Contributor

@Luberen The documentation is at the bottom of this article.

I think your format will be:

"sourceFileMap": {
     "c:\\": "C:\\"
}

@DemoCrazer
Copy link
Author

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

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

Now it works fine :)

@AchalaSB
Copy link

AchalaSB commented Aug 2, 2018

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.

@Deshwal36
Copy link

Windows :

Please make sure if you have gdb.exe in your bin folder
C:\MinGW\bin\gdb.exe
if not then you can directly install the gdb.exe by following commands -
In command prompt browsed to C:\MinGW\bin and run : mingw-get.exe to install gdb

C:\MinGW\bin>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.

@Fabxx
Copy link

Fabxx commented Aug 6, 2021

I'm having the same problem, trying the solution mentioned above for the source file map, but i'm on Debian linux distro based. INstead of C:\ what should i put?

@sean-mcmanus
Copy link
Collaborator

@WardenGnaw Do you know?

@morfi11
Copy link

morfi11 commented Mar 21, 2022

I am using remote-ssh with an ubunto server. trying to use gdb to view a coredump file.
Cannot get the thing to find my source file - keep getting the "file not found" popup. It always shows the filename with no path.

I have this in my launch.json: (just added the soureFileMap now to fix the absolute path - does not help)

    {
        "name": "View coredump",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceRoot}/build/app/myapp",
        "args": [],
        "cwd": "${workspaceRoot}",
        "coreDumpPath": "/tmp/lastcoredump.core",
        //"preLaunchTask": "select coredump",
        "MIMode": "gdb",
        "problemMatcher": {
            //"base" : "$gcc",
            "fileLocation" : "absolute",
            "sourceFileMap": {
                "\\mnt": "${workspaceRoot}",
                "/mnt" : "${workspaceRoot}"
            }
        }
    }

@ehsanakrami
Copy link

ehsanakrami commented Oct 12, 2022

In my case, replacing ${fileDirname} , ${workspaceRoot} with ${workspaceFolder} resolved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants