vscode编辑器很牛逼,但是对小白来说用cmake配置完整版调试c++有很大难度。当然我也是小白,摸索了老长时间,整理如下:
project(MYPROJECT)
# 方法一:将*.cpp全放进SOURCES
set( SOURCES
./main.cpp
./swap.cpp
)
# 方法二:将*.cpp全放进SOURCES
# aux_source_directory(. SOURCES)
add_executable(main ${SOURCES})
# add_executable(main main.cpp swap.cpp)
{
// 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) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/main.exe", // gdb执行的调试文件
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}", //文件所在的文件夹路径,也即/home/Coding/Test/.vscode
"environment": [],
"externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台
"MIMode": "gdb",
"miDebuggerPath": "gdb", // 改为gdb
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
// 此处配置为debug前需要执行的任务,是task.json里面的"label"
"preLaunchTask": "Build"
},
]
}
{
"version": "2.0.0",
"options": {
"cwd": "${workspaceFolder}/build"
},
"tasks": [
{
"type": "shell",
"label": "cmake",
"command": "cmake",
"args": [
".."
]
},
{
"label": "make",
"group": {
"kind": "build",
"isDefault": true
},
"command": "mingw32-make.exe",
"args": [
]
},
{
"label": "Build", // launch.json里面的preLaunchTask
"dependsOn":[
"cmake",
"make"
]
}
]
}
调试快捷键:
F5 开始调试
F10 步进