踩坑 Sophus 模板库安装及编译(视觉SLAM 十四讲第二版 ch4 )

在《视觉slam十四讲》第二版中,第4、7、8、9、10讲都需要Sophus库,因此我们需要安装Sophus库,并且需要的是Sophus模板库,因此很多人因为安装了非模板版本导致报错,下面提供Sophus模板版本安装方式,以及对应不报错版本。

1.查看eigen版本

pkg-config --modversion eigen3

只要是 3.3以上的版本即可

2.安装 fmt (8.1.1版)

官网进入,然后下载Tag里的fmt-8.1.1.zip,解压

cd fmt
mkdir build
cd build
cmake ..
make
sudo make install

3.安装Sophus模板库 

git clone https://github.com/strasdat/Sophus.git
cd Sophus
mkdir build
cd build
cmake ..
make 
sudo make install

最后虽然书上说只需编译,无需安装,但是如果不进行 sudo make install,cmake时会找不到Sophus的位置。要是不想更改cmakelist.txt,就进行安装,让 find package 自己去找路径。

安装完成后,然后去正常编译视觉slam十四讲里的源码即可

4. 一些编译问题

ch4:

错误1:cmake ..时:

CMake Error at CMakeLists.txt:9 (add_executable):
  Target "useSophus" links to target "Sophus::Sophus" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

解决方案:

在CMakeLists.txt中:加入

set(Sophus_DIR "/home/你自己的路径/Sophus/build")

错误2:make 时:

[ 50%] Linking CXX executable trajectoryError

/usr/bin/ld: CMakeFiles/trajectoryError.dir/trajectoryError.cpp.o: in function `std::make_unsigned<int>::type fmt::v8::detail::to_unsigned<int>(int)':

trajectoryError.cpp:(.text._ZN3fmt2v86detail11to_unsignedIiEENSt13make_unsignedIT_E4typeES4_[_ZN3fmt2v86detail11to_unsignedIiEENSt13make_unsignedIT_E4typeES4_]+0x23): undefined reference to `fmt::v8::detail::assert_fail(char const*, int, char const*)'

解决方案

没有链接fmt库,链接上fmt 库就没问题了,将example中的CMakeLists.txt中:

target_link_libraries(trajectoryError ${Pangolin_LIBRARIES} ${FMT_LIBRARIES})改为

target_link_libraries(trajectoryError ${Pangolin_LIBRARIES} ${FMT_LIBRARIES} fmt)


错误3:./example/trajectoryError时:

trajectory ./example/groundtruth.txt not found.
trajectory ./example/estimated.txt not found.
trajectoryError: /home/tzy/shijue_ws/src/slambook14/ch4/example/trajectoryError.cpp:22: int main(int, char**): Assertion `!groundtruth.empty() && !estimated.empty()' failed.
Aborted (core dumped)

解决方案

因为我们是在 build下执行命令,如果使用文件的相对路径:则修改trajectoryError.cpp,改成:

string groundtruth_file = "../example/groundtruth.txt";
string estimated_file = "../example/estimated.txt";

保存重新 make 后执行: ./example/trajectoryError

  • 9
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值