Vscode "Unable to open [file]: Unable to read file" message when clicking on an error

Viewed 45078

I get this message when I click on a warning. This is a screenshot of the case. enter image description here

The error reads,

Unable to open 'warning.cpp': Unable to read file '/Users/dimen/code/C++/Users/dimen/code/C++/warning.cpp' (Error: Unable to resolve non-existing file '/Users/dimen/code/C++/Users/dimen/code/C++/warning.cpp').

My script is located in /Users/dimen/code/C++/warning.cpp so vscode reiterates the path for some reason.

I suspected that the linter setting must've been written erroneously but I'm not sure where I should edit. As some side notes,

  • Using Microsoft's C/C++ extension.
  • tasks.json have been customized so that all the builds go inside the build folder
6 Answers

I was facing this issue also.

For resolving this issue, I closed the VSCode and again imported folder again as Path of folder got changed in mine conditions.

If this doesn't work, you can uninstall VSCode and then reinstall it.

You need to edit the problemMatcher part of tasks.json so that it has a variable called fileLocation that is set to absolute. Here is an example of what it should look like:

"problemMatcher": {
    "base" : "$gcc",
    "fileLocation" : "absolute"
}

I hope this helps.

Check this link. It seems to require detailed configurations for the directory. In task.json the problemMatcher takes the file directory as relative so you got repeating path. Setting "fileLocation" to "absolute" works on my laptop.

For me this worked in tasks.json:

{
    "tasks": [
        {
            //"type": "cppbuild",
            "label": "build my project",
            "command": "/home/user/path/build.bash",
            "args": [
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": {
                "base": "$gcc",
                "fileLocation": "absolute",
            },
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

For some reason i had to specifically remove "type": "cppbuild" for it to work.

I fixed this issue by making a change in 'launch.json' file. I changed the value of "cwd" below "name": "(gdb) Launch eds" in "configurations" field. I set it to the absolute path of the folder containing the project. Below is my launch.json file. I'm using VS Code on Ubuntu.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch eds",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build_x86_debug/bin/fcc",
            "args": ["-a=${workspaceFolder}/build_x86_debug/bin/", "-d=${workspaceFolder}/build_x86_debug/bin/", "-c=${workspaceFolder}/build_x86_debug/bin/"],
            "stopAtEntry": false,
            "cwd": "/home/aiden/dev2",
            "environment": [{"name": "LD_LIBRARY_PATH", "value": "/usr/lib:${workspaceFolder}/build_x86_debug/bin:${workspaceFolder}/pocolib1.7.5"}],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        },
        {
            "name": "Launch",
            "type": "lldb",
            "request": "launch",
            "program": "${workspaceFolder}/build_x86/bin/emvadapter",
            "cwd" : "/home/vendor",
            "env" : { "LD_LIBRARY_PATH":"/home/vendor/lib" }

        },
        {
            "name": "Unit Tests",
            "type": "lldb",
            "request": "launch",
            "program": "${workspaceFolder}/build_x86/bin/",
            "linux": { "cwd": "${workspaceFolder}/vendor"}
        }
    ]
}

I got this too on ApiLogicServer, which uses this feature extensively.

Took a few, but this resolved it by clicking container (lower left) and then rebuild-container:

enter image description here

Related