参考教程
参考了一篇博客:Ubuntu16.04下配置VScode的C/C++开发环境
亲测在Ubuntu20的vscode下是有效的。
配置步骤
安装C/C++插件
在插件商店中搜索C/C++
,安装完成。
创建两个文件
首先创建一个文件,在你的当前目录下,并将其命名为.vscode
,在下面你可以创建两个文件:launch.json
和 tasks.json
下面是我的两个文件
launch.json
{
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/main.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "build",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "g++",
"args": ["-g", "${file}","-std=c++11", "-o", "${fileBasenameNoExtension}.out"]
}
]
}