我這裏配置的是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"
]
}
]
}