Ubuntu配置Visual Studio Code C++开发环境
安装Visual Studio Code和C++插件
创建工程并添加配置文件及任务文件
1、创建工程文件夹
2.创建源文件main.cpp ,main.out
代码如下
#include<iostream>
using namespace std;
int main()
{
cout<<"hello world"<<endl;
return 0;
}
3、配置launch.json文件
打开VS code 打开文件
点击开始Debug后,系统会自动生成两个文件
一个是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}/main.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"preLaunchTask": "build",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
4、任务文件task.json
修改task.json文件,具体代码如下
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0", //该tasks.json文件采用的版本号,目前默认为2.0.0版本
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": [
"-g",
"${file}",
"-std=c++11",
"-o",
"${fileBasenameNoExtension}.out"
],
"problemMatcher": [
"$gcc"
]
}
]
}
5.最后在main.cpp 上debug程序
设置断点
点击下一步
总结
在这次的实验中,我在Ubantu下面进行了配置Visual Studio Code C++开发环境,先下载了Visual Studio Code ,然后安装了C++插件,配置了C++调试的环境,需要更改launch.json,task.json两个系统自动生成的文件,然后就可以像上次实验一样,设置断点,开始调试。