详情参考官方文档
set(CMAKE_BUILD_TYPE Debug) # 首先要在CMakeList.txt中设置dubug模式
调试多个程序和调试一个程序是一样的道理,只需要后面把两个文件compounds
{
// 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": "main", // 使用哪一种调试器,gdb为gcc自带的
"type": "cppdbg", // 程序类型cpp
"request": "launch",
"preLaunchTask": "Build", // 保证该名字与task.json中的最后生成的文件相同 即:编译文件存放的位置
"program": "${workspaceFolder}/bin/main_outcar", // 生成的可执行文件的路径, 命令形式 "program": "${workspaceFolder}/your_executable",
"args": [ "/home/xxx"], //终端输入参数,不包括可执行文件 形式 "args": ["arg1", "arg2"]
"stopAtEntry": false,
"cwd": "${workspaceFolder}", //当前文件s路径
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb", // gdb的路径,默认
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
},
{
"name": "test", // 使用哪一种调试器,gdb为gcc自带的
"type": "cppdbg", // 程序类型cpp
"request": "launch",
"preLaunchTask": "Build", // 保证该名字与task.json中的最后生成的文件相同 即:编译文件存放的位置
"program": "${workspaceFolder}/bin/function_text", // 生成的可执行文件的路径, 命令形式 "program": "${workspaceFolder}/your_executable",
"args": [ ], //终端输入参数,不包括可执行文件 形式 "args": ["arg1", "arg2"]
"stopAtEntry": false,
"cwd": "${workspaceFolder}", //当前文件s路径
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb", // gdb的路径,默认
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
],
"compounds": [
{
"name": "main/test",
"configurations": ["main", "test"],
"stopAll": true
}
]
}
这个文件是通用的,直接复制粘贴即可。这个文件主要为了编译代码,所以如果不对代码修改,其实也可以不加这个文件。
{
"options": {
"cwd": "${workspaceFolder}/build"
},
"tasks": [
{
"type": "shell", // 相当于对整个文件进行编译的步骤 此处代表cmake ..
"label": "cmake",
"command": "cmake",
"args": [
".."
]
},
{
"label": "make", // 此处代表make
"group": {
"kind": "build",
"isDefault": true
},
"command": "make",
"args": []
},
{
"label": "Build", // label表示编译的文件存放的位置,要求与launch.json中的preLaunchTask相同
"dependsOrder": "sequence",
"dependsOn":["cmake","make"] // 此处表示联合两条指令
}
],
"version": "2.0.0"
}