2016-09-15 50 views
2

我想编译在Visual Studio代码一段cpp的文件,因此我设置了以下tasks.json:任务在Visual Studio代码没有找到文件

{ 
    // 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 -folder,其中是tasks.json文件所在的位置),并执行编译任务,从gcc中得到“文件未找到”作为错误。我的json代码中的问题在哪里?

回答

1

有几个问题。

  1. 您需要抑制任务名称,它也被传递给命令。如果您在“echo”命令中换出“css”,您会看到该命令正在使用Compile -02 -Wall filename.cpp -o "-o filename.cpp"执行。这使我接下来的两个问题...
    1. 您需要分隔-o和basefilename。额外的东西进入你的命令
    2. 文件名和basefilename是相同的(在我的测试)。但如果你只是想默认输出(filename.cpp - > filename.o),你甚至需要 - Ø说法?你就不能叫gcc -02 -Wall filename.cpp?如果是这样,那么你就不需要担心#2或有关如何获得不同的输出名称。

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 
       } 
      } 
     } 
    ] 
} 
相关问题