【问题标题】:VS Code unable to open files in the "PROBLEMS" tab because the path is badly constructedVS Code 无法在“问题”选项卡中打开文件,因为路径构造错误
【发布时间】:2020-02-01 00:39:06
【问题描述】:

我正在使用 Visual Studio Code 在 C++ 中进行开发,我注意到,当程序构建失败时,我无法通过单击快速访问“问题”选项卡中显示的错误行,因为 VS代码尝试以错误的路径读取文件,然后认为该文件不存在。下面的例子:

如您所见,就像 VS Code 总是在 ${workspaceFolder}/${workspaceFolder}/ 中搜索文件,而它实际上应该在 ${workspaceFolder} 中/。是否有任何配置区域可供我检查和修复此问题?

这是我的 c_cpp_properties.json

{
"configurations": [
    {
        "name": "Win32",
        "includePath": [
            "${workspaceFolder}/**",
            "C:/SFML-2.5.1/include"
        ],
        "defines": [
            "_DEBUG",
            "UNICODE",
            "_UNICODE"
        ],
        "compilerPath": "C:\\MinGW\\bin\\g++.exe",
        "cStandard": "c11",
        "cppStandard": "c++17",
        "intelliSenseMode": "clang-x86",
        "browse": {
            "path": [
                "C:/SFML/SFML-2.5.1/include"
            ]
        }
    }
],
"version": 4
}

这是 tasks.json 中的构建任务:

{
"version": "2.0.0",
"tasks": [
    {
        "type": "shell",
        "label": "Build BASIC Debug",
        "command": "C:\\MinGW\\bin\\g++.exe",
        "args": [
            "-g",
            "${workspaceFolder}\\mainBASIC.cpp",
            "-o",
            "${workspaceFolder}\\bin-debug\\DaniHash_BASIC 1.0.3d.exe",
            "-IC:\\SFML-2.5.1\\include",
            "-LC:\\SFML-2.5.1\\lib",
            "-lsfml-graphics-d",
            "-lsfml-window-d",
            "-lsfml-system-d",
        ],
        "options": {
            "cwd": "C:\\MinGW\\bin"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build"
    }
}

【问题讨论】:

    标签: c++ visual-studio-code


    【解决方案1】:

    我发现此行为与 tasks.jsonproblemMatcher 字段有关。添加一个属性来自动检测文件位置可以解决这个问题:

    "problemMatcher": [
        {
            "base":"$gcc",
            "fileLocation": ["autoDetect", "${workspaceFolder}"]
        }
    ],
    

    参考:https://code.visualstudio.com/docs/editor/tasks

    【讨论】:

      猜你喜欢
      • 2021-01-18
      • 2020-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-28
      • 2018-11-28
      • 2012-06-10
      • 2021-03-11
      相关资源
      最近更新 更多