C/C++ Development using Visual Studio Code, CMake and LLDB

概述

由于我工作环境是Linux和Mac,个人的工作目录和开发环境一直来回切换,之前一直使用emacs。不可否认,emacs非常强大和可定制化。昨天由于个人电脑系统损坏,重装了osx。在好基友的推荐下,试用vscode,发现非常不错。于是记录和分享到博客中。今天主要给大家讲解的vscode配置c/c++ ide开发环境,当然官网支持很多种可定制化的配置。

开发环境搭建

我们首先安装vscode,官网是:vscode。我们下面来安装支持c/c++开发环境的安装包。

  • cpptools
  • cmake
  • C/C++ Clang

我们在工作目录依次安装如下,c_cpp_properties.json(指定c/c++包和平台相关的配置文件),launch.json(debug 调试),tasks.json(你的编译等命令)

c_cpp_propertie.json

{
  "configurations": [
    {
      "name": "Mac",
      "includePath": [
        "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
        "/usr/local/include",
        "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include",
        "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
        "/usr/include",
        "${workspaceRoot}"
      ],
      "defines": [],
      "intelliSenseMode": "clang-x64",
      "browse": {
        "path": [
          "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1",
          "/usr/local/include",
          "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include",
          "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
          "/usr/include",
          "${workspaceRoot}"
        ],
        "limitSymbolsToIncludedHeaders": true,
        "databaseFilename": ""
      },
      "macFrameworkPath": [
        "/System/Library/Frameworks",
        "/Library/Frameworks"
      ]
    },
    {
      "name": "Linux",
      "includePath": [
        "/usr/include",
        "/usr/local/include",
        "${workspaceRoot}"
      ],
      "defines": [],
      "intelliSenseMode": "clang-x64",
      "browse": {
        "path": [
          "/usr/include",
          "/usr/local/include",
          "${workspaceRoot}"
        ],
        "limitSymbolsToIncludedHeaders": true,
        "databaseFilename": ""
      }
    },
    {
      "name": "Win32",
      "includePath": [
        "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include",
        "${workspaceRoot}"
      ],
      "defines": [
        "_DEBUG",
        "UNICODE",
        "_UNICODE"
      ],
      "intelliSenseMode": "msvc-x64",
      "browse": {
        "path": [
          "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*",
          "${workspaceRoot}"
        ],
        "limitSymbolsToIncludedHeaders": true,
        "databaseFilename": ""
      }
    }
  ],
  "version": 3
}

我们再看一下下面的debug下的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": "(lldb) Launch",
      "type": "cppdbg",
      "request": "launch",
      "program": "${workspaceFolder}/build/DemoProject",
      "args": [],
      "stopAtEntry": false,
      "cwd": "${workspaceFolder}/build",
      "environment": [],
      "externalConsole": false,
      "MIMode": "lldb"
    }
  ]
}

最后一个是tasks.json

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "echoCommand": true,
  "options": {
    "cwd": "${workspaceRoot}/build"
  },
  "tasks": [
    {
      "label": "cmake",
      "type": "shell",
      "command": "cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Debug ..",
      "group": {
        "kind": "build",
        "isDefault": true
      }
    },
    {
      "label": "make",
      "type": "shell",
      "command": "make -j 8",
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ]
}

效果

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏iOS开发攻城狮的集散地

延时操作

1384
来自专栏自由而无用的灵魂的碎碎念

让CodeRush Xpress for C#的菜单在Visual Studio 2008下显示

很多情况下,CodeRush Xpress for c#功能是靠快捷键来操作的。不过,要经常使用它的options菜单,常Shift+Ctrl+Alt+O觉得也...

973
来自专栏LeeCen

Swift Perfect - iOS消息推送(APNs)之获取 APNs 授权码

本文的原生教程请点传送门 英文版:?Perfect-Notifications 英文? 中文版:?Perfect-Notifications 中文?

1801
来自专栏拂晓风起

Flex Air 主窗口和多个子窗口从属显示

873
来自专栏.NET开发者社区

一步一步创建ASP.NET MVC5程序[Repository+Autofac+Automapper+SqlSugar](五)

时间飞逝,一个星期又过去了,今天还是星期五,Rector在图享网继续跟大家分享系列文本:一步一步创建ASP.NET MVC5程序[Repository+Auto...

23310
来自专栏张善友的专栏

Lightweight Test Automation Framework之旅

Lightweight Test Automation Framework是ASP.NET QA团队开发的自动化集成测试框架,并且应用在ASP.NET QA团队...

2189
来自专栏DeveWork

5 款前沿的WordPress主题后台选项开发框架推荐

在开发WordPress 主题的时候,借用成熟的WordPress 主题后台选项开发框架可以为我们省下不少功夫。相信你接触过不少国人做的所谓“原创”主题,一看后...

25910
来自专栏.NET技术

Visual Studio Package 插件开发

  这段时间公司新做了一个支付系统,里面有N个后台服务,每次有更新修改,拷贝打包发布包“不亦乐乎”。。。于是我想要不要自己定制个打包插件。

1323
来自专栏NetCore

用Js控制TextBox不能复制粘贴

今天项目中,有一个要求,需要有一个Textbox(WebControls),不能复制、粘贴 一开始没想到TextBox有这个事件,一直在找,找了N久,只有Wi...

24010
来自专栏小二的折腾日记

Sublime Text3使用总结

保存为Sublime Text3\Packages\User\addCurrentTime.py

712

扫码关注云+社区

领取腾讯云代金券