Is it possible to set a task.json for all c++ files in VSCode?

Viewed 1953

I'd like to give VSCode a try. Is it possible to set compile and build commands for all .cpp files? Just like in Geany? And it is possible to do that for every supported language?

Searching here and there it seems that I have to set it in task.json for each project (even the link to iostream)

2 Answers

launch.json

"version": "0.2.0",
"configurations": [
    {
        "name": "(gdb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": true,
        "MIMode": "gdb",
        "miDebuggerPath": "Example:/Your/path/to/gdb",
        "preLaunchTask": "g++",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ]
    },

tasks.json

{
    "version": "2.0.0",
    "command": "g++",
    "args": [
        "-g",
        "${file}",
        "-o",
        "${fileBasenameNoExtension}.exe"
    ],
    "problemMatcher": { "owner": "cpp", "fileLocation": ["relative", "${workspaceRoot}"], 
    "pattern": { "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$", 
        "file": 1, 
        "line": 2, 
        "column": 3, 
        "severity": 4, 
        "message": 5 } 
        } 
}

That's the solution for C/C++ Extension. Maybe you have to set a breakpoint at the end of the .cpp file. Or you can install the code-runner Extension. You can add the two files to C:/Users/someone/AppData/Roming/Code/User/ so that you can compile for all .cpp files.

Related