2016-09-15 61 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 
       } 
      } 
     } 
    ] 
} 
相關問題