创建在Visual Studio代码中构建CPP和C文件的任务

发布于 2025-01-26 13:35:10 字数 792 浏览 2 评论 0原文

我在task.json文件中的任务中有构建项目的文件:

"tasks": [
    {
        "type": "cppbuild",
        "label": "C/C++: build",
        "command": "/usr/bin/g++",
        "args": [
            "-g",
            "${workspaceFolder}/*.cpp",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}",
        ],
        "options": {
            "cwd": "${workspaceFolder}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "compiler: /usr/bin/g++"
    },

abound.json调用任务。 line 是否“ $ {workspacefolder}/*。cpp”表示任务仅构建cpp文件?如果项目同时具有 - cppc文件,该如何处理?

I have task in my task.json file in Visual Studio Code that builds project :

"tasks": [
    {
        "type": "cppbuild",
        "label": "C/C++: build",
        "command": "/usr/bin/g++",
        "args": [
            "-g",
            "${workspaceFolder}/*.cpp",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}",
        ],
        "options": {
            "cwd": "${workspaceFolder}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "compiler: /usr/bin/g++"
    },

Task is called from launch.json. Does line "${workspaceFolder}/*.cpp" means that task builds only cpp files? How to deal if project has both - cpp and c files?

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

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

发布评论

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

评论(2

苦行僧 2025-02-02 13:35:10

G ++可以编译任何.c或.cpp文件,但仅将其视为C ++文件。
GCC可以编译任何.C或.CPP文件,但分别将其视为C ++。

compilerargs(可选)编译器参数以修改所使用的包含或定义,例如-nostdinc ++,-m32等。

您可以尝试使用GCC。

否则,如果您有一个主

#include "example.h"
#include "example2.h"

也许这可能会带来更多澄清: https:// code。 VisualStudio.com/docs/cpp/c-cpp-properties-schema-reference

G++ can compile any .c or .cpp files but they will be treated as C++ files only.
GCC can compile any .c or .cpp files but they will be treated as C and C++ respectively.

compilerArgs (optional) Compiler arguments to modify the includes or defines used, for example -nostdinc++, -m32, etc.

You could try using GCC.

Else if you have a main.cpp the uses

#include "example.h"
#include "example2.h"

compiling only the main file should work.

Perhaps this might bring some more clarification : https://code.visualstudio.com/docs/cpp/c-cpp-properties-schema-reference

潦草背影 2025-02-02 13:35:10
"tasks": [
    {
        "type": "cppbuild",
        "label": "C/C++: build",
        "command": "/usr/bin/gcc",
        "args": [
            "-g",
            "${workspaceFolder}/*.cpp",
            "${workspaceFolder}/*.c", // this should build c and cpp at the same time.
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}",
        ],
        "options": {
            "cwd": "${workspaceFolder}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "compiler: /usr/bin/gcc"
    },
"tasks": [
    {
        "type": "cppbuild",
        "label": "C/C++: build",
        "command": "/usr/bin/gcc",
        "args": [
            "-g",
            "${workspaceFolder}/*.cpp",
            "${workspaceFolder}/*.c", // this should build c and cpp at the same time.
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}",
        ],
        "options": {
            "cwd": "${workspaceFolder}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "compiler: /usr/bin/gcc"
    },
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文