cpp_0_1_vscode 环境配置

  1. Overview
  2. vscode 配置
  3. 配置 launch.json
  4. 配置 tasks.json
  5. 配置 settings.json
  6. 配置 c_cpp_proterties.json

Overview

1.vscode cpp 配置
2.配置 launch.json
3.配置 tasks.json
4.配置 settings.json
5.配置 c_cpp_proterties.json

vscode 配置

1.准备一个 .cpp 文件

#include <iostream>
using namespace std;
int main () {
  cout << "hello world" << endl;
  return 0;
}

2.左侧栏进入 Run and Debug, 选择 C++(GDB/LLDB), 选择 g++ 生成和调试活动文件, 也就是编译器: /usr/bing/g++, 参考下面 launch.json/task.json去直接配置
3.shift+cmd+p edit configurations (JSON), 参考配置文件见下方

配置 launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "lldb",
      "request": "launch",
      "name": "C++ debug",
      "program": "{fileDirname}/${fileBasenameNoExtension}",
      "args": [],
      "cwd": "${workspaceFolder}",
      "preLaunchTask": "C/C++: g++ 生成活动文件"
    },
    {
      "name": "C/C++: g++ 生成和调试活动文件",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}/.bin/${fileBasenameNoExtension}",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${fileDirname}",
      "environment": [],
      "externalConsole": false,
      "MIMode": "lldb",
      "preLaunchTask": "C/C++: g++ 生成活动文件"
    }
  ]
}

配置 tasks.json

for OSX, 在args里面设置了执行参数

  • 不想生成.DYSM文件, 需要删除args里面”-g”参数
  • 换用 cpp 11: 设置args里面”-std=c++11”
  • 设置生成的二进制文件放在.bin下面设置args里面”${fileDirname}/.bin/${fileBasenameNoExtension}”参数

完整的 task.json 文件, 如果只想编译一个文件

{
  "tasks": [
    {
      "type": "cppbuild",
      "label": "C/C++: g++ 生成活动文件",
      "command": "/usr/bin/g++",
      "args": [
        "-std=c++11",
        "-stdlib=libc++",
        "-fdiagnostics-color=always",
        "-Wall",
        "${file}",
        "-o",
        "${fileDirname}/.bin/${fileBasenameNoExtension}"
      ],
      "options": {
        "cwd": "${fileDirname}"
      },
      "problemMatcher": [
        "$gcc"
      ],
      "group": {
        "kind": "build",
        "isDefault": true
      },
      "detail": "调试器生成的任务。"
    }
  ],
  "version": "2.0.0"
}

配置 settings.json

{
  "files.associations": {
    "ostream": "cpp",
    "__bit_reference": "cpp",
    "__bits": "cpp",
    "__config": "cpp",
    "__debug": "cpp",
    "__errc": "cpp",
    "__hash_table": "cpp",
    "__locale": "cpp",
    "__mutex_base": "cpp",
    "__node_handle": "cpp",
    "__split_buffer": "cpp",
    "__threading_support": "cpp",
    "__tuple": "cpp",
    "__verbose_abort": "cpp",
    "array": "cpp",
    "atomic": "cpp",
    "bit": "cpp",
    "bitset": "cpp",
    "cctype": "cpp",
    "clocale": "cpp",
    "cmath": "cpp",
    "complex": "cpp",
    "cstdarg": "cpp",
    "cstddef": "cpp",
    "cstdint": "cpp",
    "cstdio": "cpp",
    "cstdlib": "cpp",
    "cstring": "cpp",
    "ctime": "cpp",
    "cwchar": "cpp",
    "cwctype": "cpp",
    "exception": "cpp",
    "initializer_list": "cpp",
    "ios": "cpp",
    "iosfwd": "cpp",
    "iostream": "cpp",
    "istream": "cpp",
    "limits": "cpp",
    "locale": "cpp",
    "memory": "cpp",
    "mutex": "cpp",
    "new": "cpp",
    "optional": "cpp",
    "ratio": "cpp",
    "sstream": "cpp",
    "stdexcept": "cpp",
    "streambuf": "cpp",
    "string": "cpp",
    "string_view": "cpp",
    "system_error": "cpp",
    "tuple": "cpp",
    "type_traits": "cpp",
    "typeinfo": "cpp",
    "unordered_map": "cpp",
    "variant": "cpp",
    "vector": "cpp",
    "__nullptr": "cpp",
    "__string": "cpp",
    "chrono": "cpp",
    "compare": "cpp",
    "concepts": "cpp",
    "algorithm": "cpp",
    "charconv": "cpp"
  }
}

配置 c_cpp_proterties.json

使用 shift+cmd+p , 选择 Edit Configuration (JSON)

{
  "configurations": [
    {
      "name": "Mac",
      "includePath": [
        "${workspaceFolder}/**"
      ],
      "defines": [

      ],
      "macFrameworkPath": [
        "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
      ],
      "cStandard": "c11",
      "cppStandard": "c++11",
      "intelliSenseMode": "macos-clang-arm64",
      "compilerPath": "/usr/bin/g++",
      "browse": {
        "limitSymbolsToIncludedHeaders": false
      }
    }
  ],
  "version": 4
}

转载请注明来源, from goldandrabbit.github.io

💰

×

Help us with donation