Reputation: 4114
I want to compile a cpp-file in Visual Studio Code, and thus I set up the following tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "g++-5",
//"args": ["-O2", "-Wall", "${file}", "-o ${fileBasename}"],
"isShellCommand": true,
"tasks": [
{
"taskName": "Compile",
// Make this the default build command.
"isBuildCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "always",
// No args
//"args": ["all"],
"args": ["-O2", "-Wall", "${file}", "-o ${fileBasename}"],
// Use the standard less compilation problem matcher.
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
But now if I switch to the file in question (which is located next to the .vscode
-folder, where the tasks.json-file is located), and execute the compile-task, I get "file not found" as error from gcc. Where is my problem in my json-code?
Upvotes: 2
Views: 2125
Reputation: 9232
There are a couple problems.
Compile -02 -Wall filename.cpp -o "-o filename.cpp"
. Which brings me to the next two issues...
gcc -02 -Wall filename.cpp
? If so, then you don't need to worry about #2 or about how to get a different output name.tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "gcc",
"isShellCommand": true,
"tasks": [
{
"taskName": "Compile",
// This prevents passing the taskName to the command
"suppressTaskName": true,
// Make this the default build command.
"isBuildCommand": true,
"showOutput": "always",
"args": ["-O2", "-Wall", "${file}"],
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}
Upvotes: 1