【问题标题】:Vscode "Unable to open [file]: Unable to read file" message when clicking on an error单击错误时的Vscode“无法打开[文件]:无法读取文件”消息
【发布时间】:2020-06-13 18:13:56
【问题描述】:

我在单击警告时收到此消息。这是案例的截图。

错误读取,

无法打开“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 出于某种原因重复了路径。

我怀疑 linter 设置一定是写错了,但我不确定应该在哪里编辑。作为一些旁注,

  • 使用 Microsoft 的 C/C++ 扩展。
  • tasks.json 已经过定制,以便所有构建都放在 build 文件夹中

【问题讨论】:

  • 你解决过这个问题吗?我有同样的问题
  • 我也有同样的问题。不知道怎么解决
  • 我也在寻找解决此问题的方法。我所做的只是重命名一个目录,现在这就是我在 vscode 中得到的所有内容。

标签: c++ visual-studio-code path linter


【解决方案1】:

我也遇到了这个问题。

为了解决这个问题,我关闭了 VSCode 并再次导入文件夹,因为文件夹路径发生了变化在我的情况下。

如果这不起作用,您可以卸载 VSCode,然后重新安装。

【讨论】:

    【解决方案2】:

    您需要编辑tasks.jsonproblemMatcher 部分,使其有一个名为fileLocation 的变量设置为absolute。以下是它的外观示例:

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

    我希望这会有所帮助。

    【讨论】:

      【解决方案3】:

      检查this link。似乎需要对目录进行详细配置。在task.json 中,problemMatcher 将文件目录作为相对目录,因此您有重复路径。将"fileLocation" 设置为"absolute" 可以在我的笔记本电脑上使用。

      【讨论】:

        【解决方案4】:

        对我来说,这在 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" 才能正常工作。

        【讨论】:

          【解决方案5】:

          我通过更改“launch.json”文件解决了这个问题。我在“配置”字段中更改了“名称”下方的“cwd”值:“(gdb)启动eds”。我将它设置为包含项目的文件夹的绝对路径。下面是我的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"}
                  }
              ]
          }
          

          【讨论】:

          • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
          • 这并不能真正回答问题。如果您有其他问题,可以点击 提问。要在此问题有新答案时收到通知,您可以follow this question。一旦你有足够的reputation,你也可以add a bounty 来引起对这个问题的更多关注。 - From Review
          【解决方案6】:

          我也在ApiLogicServer 上得到了这个,它广泛使用了这个功能。

          花了一些时间,但这通过单击容器(左下角)然后重新构建容器来解决它:

          【讨论】:

            【解决方案7】:

            您需要在代码中的任何位置设置断点,当执行将暂停时 - 按继续。调试器将在异常处自动停止。

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2011-11-19
              • 1970-01-01
              • 1970-01-01
              • 2021-04-01
              • 1970-01-01
              • 2022-10-13
              • 1970-01-01
              相关资源
              最近更新 更多