'Cannot build multiple CPP files with VSCode

I've followed the instructions here to setup VSCode with C++ on Windows 10 with MingGW https://code.visualstudio.com/docs/languages/cpp and I've followed the instructions at this link to create my task to build all .cpp files in the current folder VS Code will not build c++ programs with multiple .ccp source files

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

However, when attempting to build, I'm getting this error:

Starting build...
C:\msys64\mingw64\bin\g++.exe -fdiagnostics-color=always -g "C:\Users\user\Documents\CPP_test\.vscode\**.cpp" -o "C:\Users\user\Documents\CPP_test\.vscode\tasks.exe"
cc1plus.exe: fatal error: C:\Users\user\Documents\CPP_test\.vscode\**.cpp: Invalid argument
compilation terminated.

I've tried replacing the argument with \\*.cpp, /**.cpp, /*/*.cpp but none of it worked. For some reason it refuses to explode the * wildcard.

How can I make VS Code build all CPP files in the folder?



Solution 1:[1]

I think the problem has to do with the fact that I'm running the build while tasks.json is active. The problem is that **.cpp is not expanded or there is no indication that no cpp files are found. The argument itself seems to be bad, which is clearly not the case.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user2565010