为什么此任务配置不允许我编译多个C++ Windows上的VS代码中的文件?

发布于 2025-01-30 18:48:30 字数 1181 浏览 4 评论 0原文

因此,我已经查看了其他一些堆栈溢出问题,并在VS代码中尝试了一些任务文件中的一些内容,以编译多个C ++文件。但是,它似乎不起作用,并且有些困惑为什么它仍然没有链接。我更喜欢使用VS代码,而不是IDE,所以我真的很想让此工作。

main.cpp

#include <iostream>
int add(int x, int y);

int main(){
    std::cout << add(1, 1);
    return 0;
}

test.cpp

int add(int x, int y){
    return x + y;
}

任务

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "g++.exe build",
            "command": "C:\\msys64\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${workspaceFolder}/*.cpp",
                "-o",
                "${workspaceFolder}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "g++"
        }
    ]
}

​让我很棒,因为即使阅读了有关此问题的其他帖子,我似乎也无法得到这个。谢谢你!

So I have looked at some other Stack Overflow questions, and tried a few things to my task file in VS Code to compile multiple C++ files. However, it isn't seeming to work and am a bit confused why it is still not linking. I'd prefer to use VS Code and not an IDE, so I really want to get this working.

main.cpp

#include <iostream>
int add(int x, int y);

int main(){
    std::cout << add(1, 1);
    return 0;
}

test.cpp

int add(int x, int y){
    return x + y;
}

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "g++.exe build",
            "command": "C:\\msys64\\mingw64\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${workspaceFolder}/*.cpp",
                "-o",
                "${workspaceFolder}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "g++"
        }
    ]
}

My folders are as follows:

Folder Image

Any help would be amazing as I can't seem to get this even after reading other posts about this issue. Thank you!

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

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

发布评论

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

评论(2

萤火眠眠 2025-02-06 18:48:30

也许输入文件路径模式$ {workspaceFolder}/*。cpp

            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${workspaceFolder}/*.cpp", // Would you like to change it to ${workspaceFolder}\\*.cpp
                "-o",
                "${workspaceFolder}\\${fileBasenameNoExtension}.exe"
            ],

ps: ps:
您想把tasks.json放入.vscode文件夹中

Perhaps there is something wrong with input file path pattern ${workspaceFolder}/*.cpp:

            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${workspaceFolder}/*.cpp", // Would you like to change it to ${workspaceFolder}\\*.cpp
                "-o",
                "${workspaceFolder}\\${fileBasenameNoExtension}.exe"
            ],

PS:
would you like to put the tasks.json into .vscode folder

少女情怀诗 2025-02-06 18:48:30

我认为,test.cpp并未由main.cpp包括。
#include“ test.cpp”

In my opinion,the test.cpp was not been includeed by main.cpp.
#include "test.cpp"

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