Visual Studio代码中的任务找不到文件

时间:2016-09-15 07:54:29

标签: c++ json visual-studio-code

我想在Visual Studio Code中编译一个cpp文件,因此我设置了以下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
                }
            }
        }
    ]
}

但是现在如果我切换到有问题的文件(位于.vscode - 文件夹(tasks.json文件所在的文件夹)旁边)并执行编译任务,我得到&# 34;找不到文件"作为gcc的错误。我的json-code中的问题在哪里?

1 个答案:

答案 0 :(得分:1)

有几个问题。

  1. 您需要禁止任务名称,它也会被传递给命令。如果在“echo”命令中换出“css”,您将看到正在使用gcc -02 -Wall filename.cpp执行的命令。这让我想到了接下来的两个问题......
    1. 您需要分隔-o和basefilename。额外的“正在进入你的命令”
    2. filename和basefilename是相同的(在我的测试中)。但是如果你只想要默认输出(filename.cpp - > filename.o),你甚至需要-o参数吗?你不能打电话给{ // 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 } } } ] } 吗?如果是这样,那么您不必担心#2或如何获得不同的输出名称。
  2. tasks.json

    WITH cteSubjects AS (
        SELECT 'ELA'  AS Subject FROM dual
        UNION ALL
        SELECT 'M' FROM dual
        UNION ALL
        SELECT 'SCI' FROM dual
    )
    
    , cteGrades AS (
        SELECT 3 as grade_level
        FROM dual
    
        UNION ALL
    
        SELECT  c.grade_level + 1
        FROM
           cteGrades c
        WHERE c.grade_level + 1 <= 12
    )
    
    
    SELECT *
    FROM
        cteGrades g
        INNER JOIN cteSubjects s
        ON (CASE
              WHEN g.grade_level IN (5,8,11) AND s.Subject = 'SCI' THEN 1
              WHEN s.Subject <> 'SCI' THEN 1
              ELSE 0
           END) = 1
        INNER JOIN students s
        ON g.grade_level = s.grade_level