高翔博士在课程中建议使用Ubuntu版本为18.04,但是我早就安装好了20.04,不想再折腾,遂…
然而,万万没想到学习的时候遇到了好多的困难…
当然也不完全是因为版本的问题,还因为自己不细心…
学到第四课的同学,想必早就已经下载好了代码,就不在此赘述了。
为了程序的顺利运行,需要安装Pangolin、Eigen、fmt、Sophus库。在学习高翔博士课程的时候,他提到,可以不install这些库,做到了make就可以。但是在20.04版本的实践中,我发现,如果不安装的话,会造成找不到se3.hpp等文件的现象,所以还是乖乖安装吧。
sudo make install //一定不要忘记库的安装
新建build文件夹
cd slambook2/ch4/example //根据实际文件目录修改
mkdir build
文件路径在slambook2/ch4/example中
仔细看CMakeLists.txt的代码
option(USE_UBUNTU_20 "Set to ON if you are using Ubuntu 20.04" OFF)
find_package(Pangolin REQUIRED)
if(USE_UBUNTU_20)
message("You are using Ubuntu 20.04, fmt::fmt will be linked")
find_package(fmt REQUIRED)
set(FMT_LIBRARIES fmt::fmt)
endif()
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(trajectoryError trajectoryError.cpp)
target_link_libraries(trajectoryError ${Pangolin_LIBRARIES} ${FMT_LIBRARIES})
对于Ubuntu20.04,option是OFF的。根据message判断,如果不选择ON,就不能linked到fmt库,程序也就不能顺利运行。
在不更改的情况下,运行结果有如下的错误:
[ 50%] Building CXX object CMakeFiles/trajectoryError.dir/trajectoryError.o
[100%] Linking CXX executable trajectoryError
/usr/bin/ld: CMakeFiles/trajectoryError.dir/trajectoryError.o: in function `fmt::v8::detail::error_handler::on_error(char const*)':
trajectoryError.cpp:(.text._ZN3fmt2v86detail13error_handler8on_errorEPKc[_ZN3fmt2v86detail13error_handler8on_errorEPKc]+0xe): undefined reference to `fmt::v8::detail::throw_format_error(char const*)'
所以第一句要修改成:
option(USE_UBUNTU_20 "Set to ON if you are using Ubuntu 20.04" ON)
cd build
cmake ..
make
当解决了make的问题后,我试着发出运行命令:./trajectoryError,却出现了这样的结果:
trajectory ./example/groundtruth.txt not found.
trajectory ./example/estimated.txt not found.
trajectoryError: /home/filetransfer/shenlan/slambook2/ch4/example/trajectoryError.cpp:22: int main(int, char**): Assertion `!groundtruth.empty() && !estimated.empty()' failed.
已放弃 (核心已转储)
仔细看,是找不到两份轨迹的txt文件
所以在build文件夹下新建一个example的文件夹
mkdir example
然后再把两个txt文件复制到example文件夹(新建的这个example文件夹下)下
groundtruth.txt
estimated.txt
./trajectoryError