launch.json
- launch.json只需要修改一处,即
"program": "${workspaceFolder}/<executable path>"
中的<executable path>需要改写的实际可执行二进制文件的路径(包含文件名),前面的${workspaceFolder}
不需要改动。 - 注意,launch.json要和tasks.json,所以launch.json文件中的
"preLaunchTask": "Build"
要和tasks.json中的"label": "Build"
相匹配。
{
// 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}/<executable path>", // 这一行的配置项非常重要
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"internalConsoleOptions": "neverOpen",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "Build", // 这一步也配置同样很重要,这一步工作负责源代码的编译
}
]
}
tasks.json
下面的文件配置不需要做任何改动,直接复制粘贴即可使用
{
"version": "2.0.0",
"options": {
"cwd": "${workspaceFolder}/build" # "cwd"表示当前工作目录:current working directory;workspaceFolder表示工作空间文件夹
},
"tasks": [
{
"type": "shell",
"label": "cmake", // 该任务的标签是:"cmake"
"command": "cmake", // cmake任务生成makefile文件
"args": [ // cmake命令后所跟的参数,".."表示在父目录
".."
]
},
{
"label": "make", // 该任务的标签是:"label",根据makefile文件进行编译
"group": {
"kind": "build", // 当前任务所属的组是build组
"isDefault": true
},
"command": "make", // 在Windows下实际执行的命令是:mingw32-make
"args": [ // mingw32-make命令后面所跟的参数
]
},
{
"label": "Build", //这个名为"Build"的task是launch.json执行前所预先执行的任务
"dependsOn":[ // 并且这个任务又依赖"cmake"和"make"这两个任务
"cmake",
"make"
]
}
]
}