'Visual Studio Code task that takes c and cpp files
Trying to create gcc compile task for Visual Studio Code that takes both *.cpp and *.c files. I was trying to use patterns:
"${workspaceFolder}/*.c*"
This is not good, because it includes *.code-workspace file
("${workspaceFolder}/*.c*|${workspaceFolder}/*.cpp")
This is not treated at regular expression at all.
How to build pattern that takes *.c and *.cpp files?
tasks.json:
{
"type": "cppbuild",
"label": "gcc",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${workspaceFolder}/*.c",
"-pthread",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/gcc"
}
Solution 1:[1]
This tasks.josn works for me.
{
"type": "cppbuild",
"label": "gcc",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${workspaceFolder}/*.c",
"${workspaceFolder}/*.cpp", # add a new line to specify the build pattern of cpp fle
"-pthread",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: /usr/bin/gcc"
}
The structure of my demo project looks like this:
> tree .
.
??? entrypoints.cpp
??? entrypoints.h
??? main # the output binary
??? main.c
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 | ramsay |
