单击问题窗口时,在Visual Studio代码上找不到文件错误(使用make,gcc和gcc problemMatcher)

MrP*_*ayi 6 visual-studio-code vscode-settings vscode-tasks

我在一个使用"make和gcc"编译所有模块的项目上工作.这些模块位于自己的文件夹中,并具有自己的Makefile.全局Makefile调用它们以编译二进制文件.

所以现在我尝试使用Visual Studio Code作为我的IDE.我已经设置了编译环境并且运行良好.

唯一的问题是,只要有一些警告/编译,点击它们就不会打开正确的文件.我的工作目录类似于下面显示的简化代码.

D:\SO
|-- common
|   |-- main.c
|   `-- Makefile
`-- Makefile
Run Code Online (Sandbox Code Playgroud)

从任务我将调用外部Makefile,它将调用Makefile内部常见.而在main.c中,我故意删除了stdio.h头文件包含,这应该显示一个隐式声明错误.但是,当我单击问题窗口上的警告时,VS代码会抛出错误,表明找不到该文件.VS Code尝试打开"D:\ SO\main.c",但文件实际上在"D:\ SO\common\main.c"中

在此输入图像描述

外部Makefile

all:
    (cd common &&  make )
Run Code Online (Sandbox Code Playgroud)

内部Makefile(公共目录内)

all:
    gcc main.c
Run Code Online (Sandbox Code Playgroud)

main.c中

int main(int argc, char *argv[])
{
    printf("Hello World");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "make",
            "command": "make",
            "type": "shell",
            "problemMatcher": [
                "$gcc"
            ]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我试图通过为fileLocation参数提供不同的组合来调整problemMatcher.但他们没有产生适当的结果.所以我没有把它包括在内.

我在Windows 10 1607 x64上使用Visual Studio Code 1.14.2和mingw-gcc.

sea*_*ern 1

这不是您问题的答案,但我希望这将是 Microsoft 或其他人可以提供的任何解决方案的先决条件。

您的嵌套 Makefile 中有一个错误。你永远不应该在 Makefile 中执行此模式:

cd somewhere; make target
Run Code Online (Sandbox Code Playgroud)

cd不必要的(见下文),但直接使用make是有问题的。这种模式会扰乱 make 的一次调用将信息传递给子 make 的能力。特别是,它搞乱了并行 make。它还make使用当前 shell 路径进行调用,该路径可能不是make最初使用的路径。您应该始终使用此模式

$(MAKE) -C somewhere target
Run Code Online (Sandbox Code Playgroud)

-C dir参数告诉 make 在哪里设置其当前工作目录。并且 using$(MAKE)允许传递标志和参数。

由于这是推荐的嵌套 Makefile 模式,因此我认为 vscode 为确定适当的内容所做的任何解析都fileLocation可能需要它。