我这里配置的是Linux下的VSCode,使用的编译器是GCC,调试器是GDB
配置前先在终端中输入gcc,gdb(按q退出)看一下是否安装了g++和gdb
如果没有安装,deepin下直接输入
sudo apt-get install g++
sudo apt-get install gdb
sudo apt-get install gcc
先配置launch.json,这里面是关于C++或者C语言调试的配置
launch.json
这里有几个地方要注意,
- “preLaunchTask”: “gcc”,这句话表示在启动调试之前需要进行的任务,调试之前肯定是要编译撒,gcc这个值是后面task.json中label标签的值,你也可以取其他的。
- program这个标签中的值,注意要和后面的task.json中的cwd以及args标签中-o参数的值要对应。task.json中的cwd和"-o","${fileBasenameNoExtension}"决定了编译输出的文件名以及位置。program的值需要和这个位置一样,调试器才能找到该位置。
{
// 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": "C++ (gdb)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"preLaunchTask": "gcc",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
]
}
]
}
然后是关于C++编译的配置
task.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "gcc",
"command": "/usr/bin/gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileBasenameNoExtension}"
],
"options": {
// "cwd": "/usr/bin"
"cwd": "${workspaceFolder}/build"
},
"problemMatcher": [
"$gcc"
]
}
]
}