如何使用 Linux 风格的 gcc 错误设置 VSCode 的问题匹配器

How to set up VSCode's problem matcher with Linux-style gcc errors

我在 Windows 7 上使用 VSCode,安装了 MSYS2 + mingw-w64-x86_64-gcc + base-devel

我的项目 tasks.json 运行 make 要构建的命令:

{
    "tasks": [
        {
            "type": "shell",
            "label": "build",
            "command": "make",
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ],
    "version": "2.0.0"
}

问题是 GCC 通过以下方式生成错误消息:

src/src_file.cpp:773:59: error: comparison of integer expressions of different signedness

$workspaceFolder变量中存储的工程路径为D:\myproject.

文件的真实路径是D:\myproject\tools\src\src_file.cpp。在这种情况下,我不知道如何设置问题匹配器。我想 Linux 样式的斜线会影响问题,但我不确定。我试图为匹配器设置 regexp,但是我无法让它工作。

更新:

实际上斜杠和反斜杠不影响结果。

使用这个问题匹配器,使用 $gcc 作为基础并定义文件位置

  "problemMatcher": {
    "base": "$gcc",
    "fileLocation": ["relative", "${workspaceFolder}/tools"]
  }

编辑

删除了 src,因为它已经是错误消息的一部分。 (没看出来)