如果没有安装VScode的话,可以去点击官网下载
如果已经安装了VScode,可以直接把ORBSLAM的工程文件夹拖到VScode中,系统会提示是否添加C/C++编译工具,直接安装即可,安装过程中也可以安装一下cmake
将ORBSLAM的工程文件夹拖到VScode后,系统会自动生成.vscode的文件夹,里头会有个tasks.json的文件
里头一开始长这样:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ 生成活动文件",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
将其修改为如下:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "./build.sh"
}
]
}
在.vscode中在添加launch.json文件
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "/home/athrunsunny/slam_project/ORB_SLAM2/Examples/Monocular/mono_tum",
"args": ["/home/athrunsunny/slam_project/ORB_SLAM2/Vocabulary/ORBvoc.txt",
"/home/athrunsunny/slam_project/ORB_SLAM2/Examples/Monocular/TUM1.yaml",
"/media/athrunsunny/DATA/slam_data/rgbd_dataset_freiburg1_desk"],
"stopAtEntry": false,
"preLaunchTask": "build",//这一步的build与tasks.json中的type名字相同
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
在build.sh中修改为debug
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
make -j4
配置好后点击vscode界面最下方的build,等待编译即可,编译成功就会看到下图
根据launch中program的设置在vscode最下方选择启动文件,比如我这里是使用单目的mono_tum,根据自己的文件路径配置好参数,可以点击gdb启动试试能不能正常运行。
之后就可以自行打断点进行调试