VSCode configure C++ dev environment

claim

use CMake to build the project.

For debugging, VSCode's CMake plugins needs cmake version >=3.7.1, and ubuntu16.04 apt gives cmake 3.5, thus I don't use VSCode CMake extension. I'll use VSCode's tasks, they are flexible.

steps

create backbone code

Create your codes, including:

  • CMakeLists.txt
  • compile.sh
  • src/

You can copy from my template.

create build and run tasks (tasks.json)

Use Ctrl+Shift+P command, and select >tasks: configure task, then choose other build systems.

Then in tasks.json, write these (including the building and run tasks):

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "CMake build",
"type": "shell",
"command": "./compile.sh",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
},
{
"label": "run",
"type": "shell",
"command": "./build/blob_demo",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
]
}
]
}

Then, Ctrl+Shift+P, type Tasks: Run Task, choose build or run tasks that you just created.

debug the program (launch.json)

Since I use cmake to build my project, I set debug mode support in compile.sh, which actually pass -DCMAKE_BUILD_TYPE=Debug to cmake.

Go to debugger button, and add a new configuration, by choosing C++(GDB/LLDB). This will create a launch.json file. Its content would be like this:

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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/blob_demo", #!! change here for your config
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}

Then, in any of your .cpp file, clicking a breakpoint, and in debugging button page, start it.

vscode c++ cmake template project的更多相关文章

  1. 使用VSCode和CMake构建跨平台的C/C++开发环境

    日前在学习制作LearnOpenGL教程的实战项目Breakout游戏时,希望能将这个小游戏开发成跨平台的,支持在多个平台运行.工欲善其事必先利其器,首先需要做的自然是搭建一个舒服的跨平台C/C++开 ...

  2. VScode 使用 CMake 入门

    参考 CMake 入门实战 在 linux 平台下使用 CMake 生成 Makefile 并编译的流程如下: 编写 CMake 配置文件 CMakeLists.txt . 执行命令 cmake PA ...

  3. vscode+MinGW+cmake设置轻量ide

    本地随手写一些题目的时候,发现visual studio非常庞大emmm vscodevscode是一个轻量编辑器 (1)vscode插件与设置自动同步 在两个电脑上,用vscode可以同步插件 ,利 ...

  4. linux 下 VSCODE 使用CMake编译STM32程序

    项目在做什么 项目地址 本项目是为了研究MCU在linux下开发而做的 --build 存放cmake编译生成的文件 --cmake 存放cmake编译时会用到的文件,比如工具链检查.编译选项等 -- ...

  5. OpenCV300 CMake生成project在项目过程中的问题

    2015年6一个月4日本.OpenCV官网上面给出了最新版本号OpenCV.这是:3.0.0版本号,http://opencv.org/ 使用CMake它产生VS2010project流程.我遇到了一 ...

  6. ubuntu下,VSCode采用cmake编译C++工程

    首先在VSCode中下载CMake和CMake Tools两个插件. 选中CMake Tools,可以看到在VSCode中如何使用cmake编译C++工程的教程. 官网教程 最重要且最实用,看这个网址 ...

  7. 使用Vscode和Cmake打造跨平台的C++ IDE

    准备工作 Viusal Studio Code 64位 :Download Visual Studio Code - Mac, Linux, Windows Cmake 3.4 :Download | ...

  8. Vscode 格式化vue Template代码段

    1.安装 vetur 2.在User Setting中增加设置: "vetur.format.defaultFormatter.html": "js-beautify-h ...

  9. vscode, cmake编译多个C++文件

    目的是利用vscode及相关插件编译多个C++文件. 我已经装好cmake和mingw并且将它们的路径添加到系统变量path中了. vscode装上如下几个插件: 点击vscode左上角   文件-& ...

随机推荐

  1. Spring Bean定义配置

    1-定义bean 1.1 如果显示的指定了名称,IOC容器就是用这个名称 1.2 若没有显示指定名称,spring自带的BeanNameGenerator会使用自己的规则创建bean的名称(eg: 类 ...

  2. Python解析Pcap包类源码学习

    0x1.前言 ​ 在现场取证遇到分析流量包的情况会比较少,虽然流量类设备原理是把数据都抓出来进行解析,很大一定程度上已经把人可以做的事情交给了机器自动完成. ​ 可用于PCAP包分析的软件比如科来,W ...

  3. Centos 6 安装FreeSWITCH

    为了安装FreeSWITCH ,我选择的Linux是CentOS,目前最新的Centos版本是6.具体安装CentOS的是步骤详见网上的其它资料,本节的主要目的是为了记录FreeSWITCH的安装过程 ...

  4. ebs 12.1.1打中文补丁

    环境变量设置 oracle 用户,应用env环境变量 . /u01/app/db/tech_st/11.1.0/PROD_erpapp1.env alias s='sqlplus / as sysdb ...

  5. Android App签名打包

    Andriod应用程序如果要在手机或模拟器上安装,必须要有签名!  1.签名的意义 为了保证每个应用程序开发商合法ID,防止部分开放商可能通过使用相同的Package Name来混淆替换已经安装的程序 ...

  6. 【原创】大叔经验分享(29)cdh5使用已存在的metastore数据库部署hive

    cdh5.16.1使用的hive版本是hive-1.1.0+cdh5.16.1+1431,详见:https://www.cloudera.com/documentation/enterprise/re ...

  7. emoji错误:ER_TRUNCATED_WRONG_VALUE_FOR_FIELD: Incorrect string value:

    1 前言 由于mysql数据库要存储微信昵称,但是当微信昵称带有emoj表情会出现标题的错误. 然后发现是emoj编码是4个字节保存的,于mysql数据库编码格式utf8默认保存的是1到3个字节. 2 ...

  8. 自定义admin(self_admin)

    admin.site.register(models.UserInfo)admin.site.register(models.Book,Book_admin)######当下面注册的这个表里面没有这个 ...

  9. VUE 脚手架项目搭建

    1. 概述 1.1 说明 vue-cli是一个官方发布vue.js项目脚手架,使用vue-cli可以快速创建vue项目.GitHub地址是:https://github.com/vuejs/vue-c ...

  10. Confluence 6 配置服务器基础地址

    服务器基础地址(Server Base URL)是用户访问 Confluence 的 URL 地址.这个基础的 URL 地址必须与你在浏览器中访问 Confluence 中的地址. Confluenc ...