Vscode g++ it isn’t finding .cpp definition files

In your tasks.json you are using the default ${file} which means compile only the active file and not all source files in your folder structure.

The VSCode documentation explains how to fix this for the case of all source files in the same folder here: https://code.visualstudio.com/docs/cpp/config-linux#_modifying-tasksjson

The fix is to replace ${file} with "${workspaceFolder}/*.cpp"

In your case you have more than 1 folder containing source files. You can apply a similar fix to the second folder by adding: "${workspaceFolder}/classes/*.cpp"

so the whole tasks.json would be:

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

Leave a Comment