1.VSCODE下载
官网下载链接
2.VSCODE相关配置
参考链接Ubuntu系统下使用VS Code编译调试C++程序并添加外部库–忠烈
在VScode的扩展部分添加C/C++编译工具(有需要可以添加简体中文软件包让VScode各菜单变为中文,还可以添加Cmake工具)
将ORBSLAM的文件夹加入工作区中 接着crtl+shift+p打开vscode控制台输入C/Cpp: Edit configurations,就自动生成了一个c_cpp_properties.json文件,这样你就可以在该文件中编写参数来调整设置。
然后crtl+shift+p打开vscode控制台输入Tasks: Configure Tasks,再选择Create tasks.json file from templates,选择Others模板,就自动生成了一个tasks.json文件,这样你就可以在该文件中编写参数来调整设置。
然后直接点击左侧边栏的Debug图标或者Ctrl+Shirft+D,进行运行,此时会弹出让你选择编译器,确定编译器就自动生成了launch.json文件。
以上三个文件是VScode下的配置文件。
我的配置文件如下:
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include/eigen3"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "./build.sh"
}
]
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "/home/cch/Desktop/data-slam/ORB_SLAM2-master/Examples/Monocular/mono_kitti",
"args": ["/home/cch/Desktop/data-slam/ORB_SLAM2-master/Vocabulary/ORBvoc.txt",
"/home/cch/Desktop/data-slam/ORB_SLAM2-master/Examples/Monocular/KITTI00-02.yaml",
"/home/cch/Desktop/data-slam/data/00"],
"stopAtEntry": false,
"preLaunchTask": "build",//这一步的build与tasks.json中的type名字相同
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
launch.json中加入preLaunchTask是每次运行都运行最近更改的程序,。
3.修改build.sh
orbslam2和3中默认的辨认模式是release模式,需要将其更改为Debug模式才能进行调试
将编译的最后一部分cmake … -DCMAKE_BUILD_TYPE=Release进行更改
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
make -j8
make -j4 或者-j8根据自己机器进行更改。
4.orbslam2和orbslam3编译过程出现的问题
orbslam2中usleep报错 在报错文件下加入#include<unist.h>
orbslam3使用debug编译过程中消耗的内存很大,可能会出现卡死的情况,我在笔记本上4核编译只编译出来一次,后面在台式8核16G上编译成功(这个过程中也卡住了重启了一次)
orbslam2使用debug编译过程比较顺利