设置:Linux下VS Code中的C ++(tasks.json和launch.json)

时间:2019-06-01 11:25:37

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

我的目标是为Linux(Ubuntu)下的C ++开发设置VS Code。我看了很多教程/视频和official documentation for WSL。不幸的是,我很难将tasks.jsonlaunch.json组合在一起以构建和调试“纯Linux /无WSL”。我正在寻找这两个文件的最新版本,这些版本尽可能通用(在json文件中尽可能使用变量)。

非常感谢您!

PS:我的c_cpp_properties.json当前看起来像这样:

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/g++",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

1 个答案:

答案 0 :(得分:2)

尝试以下.vscode/launch.json

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "name": "g++ build and debug active file",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}/${fileBasenameNoExtension}",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "gdb",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ],
      "preLaunchTask": "g++ build active file",
      "miDebuggerPath": "/usr/bin/gdb"
    }
  ]
}

还有.vscode/tasks.json

{
  "tasks": [
    {
      "type": "shell",
      "label": "g++ build active file",
      "command": "/usr/bin/g++",
      "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}"
      ],
      "options": {
        "cwd": "/usr/bin"
      }
    }
  ],
  "version": "2.0.0"
}