简体   繁体   English

如何设置Visual Studio Code problemMatcher以匹配C ++错误?

[英]How do I set up Visual Studio Code problemMatcher to match C++ errors?

I set up a task for building code in Visual Studio Code (similar to How do I set up VSCode to compile C++ code? ), but the regex is not matching the output from g++. 我在Visual Studio Code中设置了一个构建代码的任务(类似于如何设置VSCode来编译C ++代码? ),但正则表达式与g ++的输出不匹配。 Is there something I am doing wrong? 有什么我做错了吗? This is on MacOS Sierra. 这是在MacOS Sierra上。

I have a source file called ItemAssignmentMatrix.cpp with an error line in it on line 15. 我有一个名为ItemAssignmentMatrix.cpp的源文件,第15行有一个错误行。

thisisanerror;

My tasks.json problemmatcher pattern regexp looks like this: 我的tasks.json problemmatcher模式regexp看起来像这样:

{
    "version": "0.1.0",
    "command": "make",
    "isShellCommand": true,
    "showOutput": "always",
    "echoCommand": true,
    "suppressTaskName": true,
    "tasks" : [
        {
            "taskName": "clean",
            "args": ["-f" "${workspaceRoot}/Makefile" "clean"]
        },
        {
            "taskName": "build",
            "isBuildCommand": true,
            "args": ["-f" "${workspaceRoot}/Makefile"],
            // Use the standard less compilation problem matcher.
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": ["relative", "${workspaceRoot}"],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        }
    ]
}

When I execute this task, my Makefile (using g++) outputs an error line like: 当我执行此任务时,我的Makefile(使用g ++)输出一个错误行,如:

g++ -g -Wall -c -o obj/Darwin_x86_64/ItemAssignmentMatrix.obj src/ItemAssignmentMatrix.cpp
src/ItemAssignmentMatrix.cpp:15:1: error: C++ requires a type specifier for all declarations
thisisanerror;
^
1 error generated.
make: *** [obj/Darwin_x86_64/ItemAssignmentMatrix.obj] Error 1

So the task executes the Makefile properly, but the Problem Matcher doesn't match the regular expression, all the output just shows up as text in the output window. 因此,任务正确执行Makefile,但问题匹配器与正则表达式不匹配,所有输出只在输出窗口中显示为文本。

The regexp seems to be the same as given in https://code.visualstudio.com/docs/editor/tasks . regexp似乎与https://code.visualstudio.com/docs/editor/tasks中给出的相同。

I tried entering the regexp and the output in https://regex101.com , and it also doesn't seem to find a match. 我尝试在https://regex101.com中输入正则表达式和输出,但它似乎也找不到匹配项。

I assume this is a problem with the regexp, but I don't understand regexp syntax well enough to debug this at this point. 我认为这是regexp的一个问题,但我还不了解regexp语法,以便在此时调试它。

Is there some reason why this expression isn't matching the output, or is there something else wrong with my Problem Matcher? 是否有某些原因导致此表达式与输出不匹配,或者我的问题匹配器是否存在其他问题? Thanks in advance for any help you can provide. 提前感谢您提供的任何帮助。

There's a built-in Problem Matcher for GCC's output. GCC的输出有一个内置的问题匹配器。 Try the following: 请尝试以下方法:

        "problemMatcher": "$gcc"

It defaults to relative paths to the workspace root. 它默认为工作空间根目录的相对路径。 You can change that using 你可以改变它

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

for example. 例如。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何设置Vim以使用Visual Studio 2010的C ++编译器进行编译? - How do I set up Vim to compile using Visual Studio 2010's C++ compiler? 如何在 C++ Visual Studio 中使用 alt 代码符号 - How do I use alt code symbols in c++ visual studio 如何在Visual Studio Code中为可执行文件和库设置python环境路径 - How can I set up a python environment path for executable and libraries in Visual Studio Code 如何从Visual Studio 2003 C ++ .NET中排除特定的.dll? - How do I exclude specific .dlls from Visual Studio 2003 C++ .NET? 如何在 Visual Studio 2019 中有条件地编译 c++ 源文件? - How do I conditionally compile c++ source files in Visual Studio 2019? 解密将Visual C ++ 6项目升级到Visual Studio 2008中的错误 - Deciphering errors in upgrading a Visual C++ 6 project to Visual Studio 2008 如何在Visual Studio(C ++)中将文字汉字字符串分配给wchar_t *? - How do I assign a literal chinese string to a wchar_t* in visual studio(c++)? 如何在 Visual Studio c++ 项目中指定“任何大于 10.0 的 Windows SDK 版本”? - How do I specify "any Windows SDK version greater than 10.0" in a Visual Studio c++ project? 使用Visual Studio 2010,如何为Visual C ++ Win32控制台应用程序提供输入? - Using Visual Studio 2010, how do I provide input to a Visual C++ Win32 Console Application? C++、Visual-Studio:是否可以创建一个可执行文件来设置环境变量然后执行? - C++, Visual-Studio: Is it possible to create an executable that would set up enviroment variables and than execute?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM