arc_lupus
arc_lupus

Reputation: 4114

Task in Visual Studio Code does not find file

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

Answers (1)

Llewey
Llewey

Reputation: 9232

There are a couple problems.

  1. You need to suppress the task name, it is being passed to the command as well. If you swap out "css" in the command for "echo", you'll see that the command being executed with Compile -02 -Wall filename.cpp -o "-o filename.cpp". Which brings me to the next two issues...
    1. You need to seperate -o and basefilename. Extra "s are making their way into your command
    2. filename and basefilename are the same (in my tests). But if you just want the default output (filename.cpp -> filename.o), do you even need the -o argument? Can't you just call 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

Related Questions