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

6

18

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
Selangor answered 1/3, 2020 at 4:51 Comment(3)
Did you ever fix this? I have the same problemIrritation
I have the same problem. I don't know how fix itRuination
I am also looking for a fix for this. All I did was rename a directory and now this is all I ever get in vscode.Matey
E
9

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.

Enjoin answered 29/1, 2021 at 9:29 Comment(0)
B
4

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.

Bessette answered 25/4, 2020 at 16:9 Comment(0)
H
3

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.

Hannis answered 14/4, 2020 at 3:42 Comment(0)
B
0

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.

Bullis answered 15/8, 2021 at 14:39 Comment(0)
C
0

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"}
        }
    ]
}
Cochin answered 14/9, 2021 at 3:7 Comment(2)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Coniferous
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From ReviewProtect
M
0

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

Megaera answered 30/9, 2021 at 17:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.