最大的坑,就是不能编译octovis,octovis需要 For the viewer octovis: Qt4, OpenGL, QGLViewer (optional)
https://github.com/OctoMap/octomap/tree/devel/octomap
我的ubuntu22.04,装不上这三个库。
E: Unable to locate package libqt4-dev
E: Unable to locate package libqt4-opengl-dev
E: Unable to locate package libqglviewer-dev-qt4
octovis应该就是个可视化的东西,我估计是不影响Octomap的使用,故且就先不用Octovis了。
只安装一个doxygen就好了。
创建工作空间文件夹,在里面再创建include,src,ThirdParty三个文件夹,build.sh 和 CMakeListx.txt文件。
进入ThirdParty文件夹
cd ThirdParty
git clone https://github.com/OctoMap/octomap.git
把Octomap下载进来。修改Octomap的CMakeLists.txt,把与Octovis相关的都删掉,不要编译Octovis。
用vscode打开工作空间,build.sh 和CMakeLists.txt分别这样写
cd /home/user_name/test_octomap/ThirdParty/octomap
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
cd /home/user_name/test_octomap
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
make
cmake_minimum_required(VERSION 2.6)
project(test_octomap)
find_package(octomap REQUIRED)
include_directories(${OCTOMAP_INCLUDE_DIRS})
link_libraries(${OCTOMAP_LIBRARIES})
add_executable(main ./src/main.cpp)
再创建task.json launch.json c_cpp_properties.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "test_octomap",
"type": "shell",
"command": "./build.sh",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
{
// 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": "/home/user_name/test_octomap/build/main",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/home/user_name/test_octomap/ThirdParty/octomap/octomap/include"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
写一个main.cpp测试
#include
#include
#include
#include
using namespace std;
int main()
{
vector msg {"Hello", "C++", "World", "from", "VS Code", "and the C++ extension!"};
octomap::OcTree tree(0.05);
for (const string& word : msg)
{
cout << word << " ";
}
cout << endl;
}
如果我们足够幸运的话,Octomap就可以用了。