Home > Software design >  Why does this task config not allow me to compile multiple C files in VS Code on Windows?
Why does this task config not allow me to compile multiple C files in VS Code on Windows?

Time:05-21

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!

CodePudding user response:

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

CodePudding user response:

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

  • Related