0、资料来源
https://www.bilibili.com/video/BV13K411M78v? p=2&spm_id_from=pageDriver
该视频讲解了vscode在window下配置单个源文件/多个源文件/CMakeLists.txt工程,如何进行调试
在此基础上测试了linux下vscode的调试,并通过测试,可以同时编译和调试
1、文件说明:
- launch.json文件
用于执行gdb的调试文件
- tasks.json文件
用于生成可执行文件的文件,这里面的配置就相当于(cmake .. make)
总结:如果只配置launch.json文件,可以执行调试,当修改代码后,还是保持原来的代码进行调试;
如果配置了tasks.json文件,当修改代码后,直接执行了make,再调试就是执行新的代码。
2、launch.json文件配置
点击:创建launch.json文件
修 改 文 件 :
program:为可执行文件路径args:为main函数提供的参数
cwd:主CMakeLists.txt路径launch.json文件(修改后) 看截图:
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid= "version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "/data/face/djtu2/test_ICCVP1.1/ICCVP1.1/output/bin/i
"args": ["ALL","/data/face/djtu2/test_ICCVP1.1/ICCVP1.1/output/b "stopAtEntry": false,
"cwd": "/data/face/djtu2/test_ICCVP1.1/ICCVP1.1/", "environment": [],
"externalConsole": false, "MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}],
//这里用于连接到tasks.json,其中Build是lable名字
"preLaunchTask": "Build"
}
]
}
3、tasks.json文件配置
tasks.json文件用于更新代码,更新可执行文件,launch.json文件调用可执行文件options:为生成的makefile文件位置
command:就是 make -j ,也可以在 后面加数字
make -j 4
"command": "make",
"args": [
"-j", "4"
]
tasks.json文件
看截图:
{
"version": "2.0.0", "options": {
//makefile位置
"cwd": "/data/face/djtu2/test_ICCVP1.1/ICCVP1.1/cmake_build/cmake_bu
},
"tasks": [
{
"label": "make", "group": {
"kind": "build", "isDefault": true
},
"command": "make", "args": [
"-j"
]
},
{
"label": "Build", "dependsOn": [
"make"
]
}
],
}
总结:所有的路径尽量都是绝对路径。
4、解决单步调试乱跳问题
参考https://www.cnblogs.com/hustdc/p/10226508.html
将CMakeLists.txt中
修改为:
默认是-O3优化代码,使用-O0不对代码进行优化