视觉工作室代码任务,该任务获取C和CPP文件

发布于 2025-01-26 05:44:02 字数 1175 浏览 2 评论 0原文

尝试创建gcc编译Visual Studio Code的任务,同时使用*。CPP*。*。C文件。我试图使用模式:

"${workspaceFolder}/*.c*"

这不好,因为它包含*。代码workspace文件,

("${workspaceFolder}/*.c*|${workspaceFolder}/*.cpp")

这根本不在正则表达式上进行处理。

如何构建*。c*。cpp文件的模式?

任务:JSON:

    {

                "type": "cppbuild",
                "label": "gcc",
                "command": "/usr/bin/gcc",
                "args": [
                    "-fdiagnostics-color=always",
                    "-g",
                    "${workspaceFolder}/*.c",
                    "-pthread",
                    "-o",
                    "${fileDirname}/${fileBasenameNoExtension}"
                ],
                "options": {
                    "cwd": "${fileDirname}"
                },
                "problemMatcher": [
                    "$gcc"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                },
                "detail": "compiler: /usr/bin/gcc"
    }

Trying to create gcc compile task for Visual Studio Code that takes both *.cpp and *.c files. I was trying to use patterns:

"${workspaceFolder}/*.c*"

This is not good, because it includes *.code-workspace file

("${workspaceFolder}/*.c*|${workspaceFolder}/*.cpp")

This is not treated at regular expression at all.

How to build pattern that takes *.c and *.cpp files?

tasks.json:

    {

                "type": "cppbuild",
                "label": "gcc",
                "command": "/usr/bin/gcc",
                "args": [
                    "-fdiagnostics-color=always",
                    "-g",
                    "${workspaceFolder}/*.c",
                    "-pthread",
                    "-o",
                    "${fileDirname}/${fileBasenameNoExtension}"
                ],
                "options": {
                    "cwd": "${fileDirname}"
                },
                "problemMatcher": [
                    "$gcc"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                },
                "detail": "compiler: /usr/bin/gcc"
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不知所踪 2025-02-02 05:44:02

tasks.josn对我有用。

        {
            "type": "cppbuild",
            "label": "gcc",
            "command": "/usr/bin/gcc",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${workspaceFolder}/*.c",
                "${workspaceFolder}/*.cpp", # add a new line to specify the build pattern of cpp fle
                "-pthread",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compiler: /usr/bin/gcc"
        }

我的演示项目的结构看起来像这样:

> tree .
.
├── entrypoints.cpp
├── entrypoints.h
├── main # the output binary
└── main.c

This tasks.josn works for me.

        {
            "type": "cppbuild",
            "label": "gcc",
            "command": "/usr/bin/gcc",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${workspaceFolder}/*.c",
                "${workspaceFolder}/*.cpp", # add a new line to specify the build pattern of cpp fle
                "-pthread",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "compiler: /usr/bin/gcc"
        }

The structure of my demo project looks like this:

> tree .
.
├── entrypoints.cpp
├── entrypoints.h
├── main # the output binary
└── main.c
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文