0

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?

user2565010
  • 1,876
  • 4
  • 23
  • 37
  • 1. I would not expect your cpp files to be in this folder: `"C:\Users\user\Documents\CPP_test\.vscode\**.cpp"` 2. I am not sure the **.cpp is correct in this case but it may not hurt. – drescherjm Apr 29 '22 at 12:23
  • I think you need to change `"${fileDirname}\\**.cpp",` to `"${workspaceFolder}/*.cpp",` like in my answer from January: [https://stackoverflow.com/a/70856902/487892](https://stackoverflow.com/a/70856902/487892) – drescherjm Apr 29 '22 at 12:25

1 Answers1

-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.

user2565010
  • 1,876
  • 4
  • 23
  • 37