点击错误时,Vscode显示“无法打开[文件]:无法读取文件”消息。

18
当我点击一个警告时,我会收到这个消息。这是该案例的屏幕截图。enter image description here 错误信息如下:无法打开'warning.cpp': 无法读取文件'/Users/dimen/code/C++/Users/dimen/code/C++/warning.cpp'(错误:无法解析不存在的文件'/Users/dimen/code/C++/Users/dimen/code/C++/warning.cpp')。我的脚本位于/Users/dimen/code/C++/warning.cpp,因此 VSCode 会重复显示路径。我怀疑代码检查设置可能写错了,但我不确定在哪里进行编辑。另外,使用 Microsoft 的 C/C++ 扩展,并且已经自定义了 tasks.json,使所有构建都进入 build 文件夹。

1
你修复过这个问题吗?我也遇到了同样的问题。 - Sean
我有同样的问题。我不知道如何解决它。 - Андрей Петров
我也在寻找这个问题的解决方法。我只是重命名了一个目录,现在在 vscode 中无论做什么都只会出现这个问题。 - kibblewhite
6个回答

8
我也曾遇到过这个问题。
解决这个问题的方法是,关闭 VSCode ,然后再次导入文件夹,因为我的条件下文件夹的路径发生了改变。
如果这不起作用,您可以卸载 VSCode,然后重新安装。

4

您需要编辑tasks.json文件中的problemMatcher部分,以便它具有一个名为fileLocation的变量,该变量设置为absolute。以下是示例:

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

我希望这可以帮到你。

3

查看此链接。它似乎需要为目录进行详细配置。在task.json中,problemMatcher将文件目录作为相对路径,因此您会得到重复的路径。将"fileLocation"设置为"absolute"可在我的笔记本电脑上运行。


0

对我来说,在 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"
}

由于某些原因,我必须明确删除"type": "cppbuild"才能使其正常工作。


0

我通过在'launch.json'文件中进行更改来解决了这个问题。我在“configurations”字段中“(gdb) Launch eds”下面的“name”中更改了“cwd”的值。我将其设置为包含项目的文件夹的绝对路径。以下是我的launch.json文件。我在Ubuntu上使用VS Code。

{
    // 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"}
        }
    ]
}

你的回答可以通过提供更多支持信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的答案是正确的。您可以在帮助中心找到有关如何编写良好答案的更多信息。 - Community
这并没有真正回答问题。如果您有不同的问题,可以通过点击提问来提出。如果您想在此问题获得新的答案时得到通知,您可以关注此问题。一旦您拥有足够的声望,您还可以添加悬赏以吸引更多关注。- 来自审核 - Rishabh Deep Singh

0

我在ApiLogicServer上也遇到了这个问题,该平台广泛使用了这个功能。

经过一番尝试,我通过点击容器(左下角)并选择重建容器来解决了这个问题:

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接