1

I can't run multiple c++ files with VS code WSL and here is my task.json:

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build",
            "detail": "Task generated by Debugger."
        }
       

I tried to change "${file}" to "${*.cpp}" and "${**.cpp}" but neither worked for me

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
  • With `"${file}"` you only build the *current* file being edited. Which is the default. I suggest you look into build-systems like `make` or meta-build/-project systems like CMake. Especially a system like CMake will make it very easy to create multi-file projects. – Some programmer dude Jul 25 '22 at 09:02
  • As a quick workaround, you need to list all individual source files (as separate arguments) for the compiler. – Some programmer dude Jul 25 '22 at 09:08
  • that tasks.json is only useful for single file projects. For more complex stuff, either use a build system like CMake (easy enough to set up for simple projects with no dependencies) or write your own Makefile – Bogdan Ionitza Jul 25 '22 at 09:20

0 Answers0