前言
前四章实践过程中比较重要的内容。
一、从Pangolin库的使用过程中了解其具体使用方法及cmake的命令编译方式:
- 使用Pangolin:
在工程的CMakeList.txt下添加以下语句:
find_package(Pangolin)
target_link_libraries(<工程名>, ${Pangolin_LIBRARIES}) - 命令使用cmake进行编译:(参考Pangolin的README.md)
创建build文件夹,在里面进行操作:
cd <工程根目录>
mkdir build
cd build
cmake …
cmake --build . - 确认库(libxx-dev)是否已安装://(参考书中P48页)
sudo updatedb //更新/var/lib/slocate.db数据库文件
locate <库名xx> //locate命令将从slocate.db文件中进行搜索
二、Sophus库的使用:
- 安装Sophus(及其依赖的fmt):
此处将从github clone最新的版本下来;因为比书中使用的更新,所以要额外安装fmt(虽然是可选的依赖,但我没处理好,那就直接装上好了)。
安装最新的Sophus:
git clone https://github.com/strasdat/Sophus.git
mkdir build
cd build
cmake ..
make
sudo make install
安装最新的fmt:
git clone https://github.com/fmtlib/fmt.git
mkdir build
cd build
cmake ..
make
sudo make install
检查是否正常安装:
cwq@ubuntu:~/2_slambook2_mycode$ ls /usr/local/include/sophus/
average.hpp rotation_matrix.hpp sim3.hpp
common.hpp rxso2.hpp sim_details.hpp
geometry.hpp rxso3.hpp so2.hpp
interpolate_details.hpp se2.hpp so3.hpp
interpolate.hpp se3.hpp types.hpp
num_diff.hpp sim2.hpp velocities.hpp
cwq@ubuntu:~/2_slambook2_mycode$
cwq@ubuntu:~/2_slambook2_mycode$ fmt --version
fmt (GNU coreutils) 8.28
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Ross Paterson.
- 因为依赖了fmt库,所以CMakeList.txt中要加上几个相关语句。完整内容如下:
# indicating required CMAKE required lowest version
cmake_minimum_required( VERSION 2.8 )
set(CMAKE_BUILD_TYPE "Debug")
project(ch4_useSophus)
find_package( Sophus REQUIRED ) #if found, xx_INCLUDE_DIRS and xx_LIBRARIES can be used below
include_directories( "/usr/include/eigen3" )
include_directories(${Sophus_INCLUDE_DIRS})
add_executable(ch4_useSophus ch4_useSophus.cpp)
target_link_libraries(ch4_useSophus ${Sophus_LIBRARIES})
find_package( fmt )
target_link_libraries(ch4_useSophus PRIVATE fmt::fmt-header-only)
#add_subdirectory(fmt EXCLUDE_FROM_ALL) #not necessary, unless target_link_libraries() doesn't use PRIVATE
#target_link_libraries(ch4_useSophus fmt-header-only)
(其中ch4_useSophus是我的文件名和工程名,需要按实际环境修改。)
(如果编译还有问题可以查阅fmt的官方文档:https://fmt.dev/latest/usage.html#usage-with-cmake)