ubuntu22.04安装Gtsam解决Eigen不兼容问题
问题描述
Ubuntu22.04下在某些依赖Eigen的项目中使用Gtsam会得到存在多个Eigen版本的错误,因为Gtsam强依赖于Eigen,如下
/usr/local/include/gtsam/base/Vector.h:76:30: error: static assertion failed: Error: GTSAM was built against a different version of Eigen
76 | GTSAM_EIGEN_VERSION_MAJOR==EIGEN_MAJOR_VERSION,
| ^
gmake[2]: *** [CMakeFiles/fastlio_reloc.dir/build.make:118: CMakeFiles/fastlio_reloc.dir/src/pose_optimizer.cpp.o] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:641: CMakeFiles/fastlio_reloc.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
解决方案
需要在编译Gtsam时将GTSAM_USE_SYSTEM_EIGEN
打开,完整编译流程如下
https://github.com/borglab/gtsam/archive/refs/tags/4.2.0.tar.gz
cd your/gtsam/workspace
mkdir build && cd build
cmake .. -DGTSAM_USE_SYSTEM_EIGEN=ON
make -j3
sudo make install
注意,还需考虑gtsam版本问题,比如4.2.0兼容情况优于4.1.x,下载地址
https://github.com/borglab/gtsam/archive/refs/tags/4.2.0.tar.gz