slambook2(ch4)—— Ubuntu18.04查看eigen库版本 + 安装Sophus库(模板类) + 例程演示

一、查看eigen库的版本

  首先查看安装的eigen库的版本号,因为slam十四讲(第二版)中安装的为模板类Sophus,该sophus对eigen库的版本有要求,如果你有3.3以下的版本的eigen,那么请先卸载:

sudo rm -rf /usr/include/eigen3 /usr/lib/cmake/eigen3 /usr/share/doc/libeigen3-dev /usr/share/pkgconfig/eigen3.pc /var/lib/dpkg/info/libeigen3-dev.list /var/lib/dpkg/info/libeigen3-dev.md5sums  

方法一

输入以下命令查看eigen版本。

cat /usr/include/eigen3/Eigen/src/Core/util/Macros.h

#或者

cat /usr/local/include/eigen3/Eigen/src/Core/util/Macros.h

在这里插入图片描述

方法二

输入以下命令查看eigen版本。

locate eigen3

在这里插入图片描述

二、安装eigen库

  安装eigen3.3以上版本(这里查看得到的版本号为3.3.4,注意3.2系列的不可以!!!)
  如果版本太低去官网下载安装,具体步骤如下:

  1. 下载安装包:eigen-版本号.tar.bz2 ,然后提取到此处
  2. 进入文件夹eigen-版本号,右键在终端打开。
  3. 进行安装
mkdir build
cd build
cmake ..
sudo make install

三、安装Sophus库(模板类)

注意,如果看网上的其他教程可能会出错,因为大部分教程是根据第一版的书,使用的是非模板类,但是这里使用的是模板类的sophus

git clone https://github.com/strasdat/Sophus.git
cd Sophus/

mkdir build
cd build
cmake ..
make
sudo make install

添加“fmt”依赖项

在安装模板类的sophus库时可能出现没有安装“fmt”库提示,如下图所示:
在这里插入图片描述

安装“fmt”库

git clone  https://github.com/fmtlib/fmt.git
cd fmt

mkdir build
cd build
cmake ..
make
sudo make install

四、例程演示

UseSophus演示

在这里插入图片描述
运行结果

/home/sfann/sf_slam_temp_code/ch4/build> /home/sfann/sf_slam_temp_code/ch4/build/useSophus
SO(3) from matrix:
2.22045e-16          -1           0
          1 2.22045e-16           0
          0           0           1
SO(3) from quaternion:
2.22045e-16          -1           0
          1 2.22045e-16           0
          0           0           1
they are equal
so3 =      0      0 1.5708
so3 hat=
      0 -1.5708       0
 1.5708       0      -0
     -0       0       0
so3 hat vee=      0      0 1.5708
SO3 updated = 
          0          -1           0
          1           0     -0.0001
     0.0001 2.03288e-20           1
*******************************
SE3 from R,t= 
2.22045e-16          -1           0           1
          1 2.22045e-16           0           0
          0           0           1           0
          0           0           0           1
SE3 from q,t= 
2.22045e-16          -1           0           1
          1 2.22045e-16           0           0
          0           0           1           0
          0           0           0           1
se3 =  0.785398 -0.785398         0         0         0    1.5708
se3 hat = 
        0   -1.5708         0  0.785398
   1.5708         0        -0 -0.785398
       -0         0         0         0
        0         0         0         0
se3 hat vee =  0.785398 -0.785398         0         0         0    1.5708
SE3 updated = 
2.22045e-16          -1           0      1.0001
          1 2.22045e-16           0           0
          0           0           1           0
          0           0           0           1
*** 已完成 ***

trajectoryError运行报错

1.运行ch4的example报错

CMakeFiles/trajectoryError.dir/trajectoryError.cpp.o:在函数‘fmt::v8::detail::error_handler::on_error(char const*)’中:
trajectoryError.cpp:(.text._ZN3fmt2v86detail13error_handler8on_errorEPKc[_ZN3fmt2v86detail13error_handler8on_errorEPKc]+0x8):对‘fmt::v8::detail::throw_format_error(char const*)’未定义的引用
CMakeFiles/trajectoryError.dir/trajectoryError.cpp.o:在函数‘std::make_unsigned<long>::type fmt::v8::detail::to_unsigned<long>(long)’中:
trajectoryError.cpp:(.text._ZN3fmt2v86detail11to_unsignedIlEENSt13make_unsignedIT_E4typeES4_[_ZN3fmt2v86detail11to_unsignedIlEENSt13make_unsignedIT_E4typeES4_]+0x21):对‘fmt::v8::detail::assert_fail(char const*, int, char const*)’未定义的引用
CMakeFiles/trajectoryError.dir/trajectoryError.cpp.o:在函数‘std::make_unsigned<int>::type fmt::v8::detail::to_unsigned<int>(int)’中:
trajectoryError.cpp:(.text._ZN3fmt2v86detail11to_unsignedIiEENSt13make_unsignedIT_E4typeES4_[_ZN3fmt2v86detail11to_unsignedIiEENSt13make_unsignedIT_E4typeES4_]+0x1f):对‘fmt::v8::detail::assert_fail(char const*, int, char const*)’未定义的引用
CMakeFiles/trajectoryError.dir/trajectoryError.cpp.o:在函数‘Sophus::SO3Base<Sophus::SO3<double, 0> >::logAndTheta() const’中:
trajectoryError.cpp:(.text._ZNK6Sophus7SO3BaseINS_3SO3IdLi0EEEE11logAndThetaEv[_ZNK6Sophus7SO3BaseINS_3SO3IdLi0EEEE11logAndThetaEv]+0x200):对‘fmt::v8::vprint(fmt::v8::basic_string_view<char>, fmt::v8::basic_format_args<fmt::v8::basic_format_context<fmt::v8::appender, char> >)’未定义的引用

  1. 应遵循调用层次,从依赖到被依赖。所以在CMakeLists.txt中添加:
target_link_libraries(trajectoryError ${Sophus_LIBRARIES} fmt)

trajectoryError依赖于Sophus,Sophus依赖于fmt。
在这里插入图片描述

  1. 路径问题

报错:

trajectory ./example/groundtruth.txt not found.
trajectory ./example/estimated.txt not found.
trajectoryError: /home/haha/slambook2/ch4/example/trajectoryError.cpp:22: int main(int, char**): Assertion `!groundtruth.empty() && !estimated.empty()' failed.
已放弃 (核心已转储)

还是trajectoryError.cpp中地址的问题。

解决办法:

  我们打开源码trajectoryError.cpp把本来写的是 ./examples/groundtruth.txt 改成../../examples/groundtruth.txt因为你观察外边的目录结构,就发现这个txt文件是存在examples下面的,但是呢你使用KDevelop执行的时候,是在examples/build下执行的,所以要先退出build 再退出examples 然后 /examples/groundtruth.txt

即:

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

在这里插入图片描述
运行结果
在这里插入图片描述

  • 17
    点赞
  • 78
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值