在随高博的《SLAM十四讲》学习时,安装ceres遇到了一些问题,在此记录下来以供参考。
第一部分是使用高博给的ceres包安装,笔者在这里没有解决好其中出现的错误,这里仅给出一个解决方案供大家测试。
第二部分是使用源码安装ceres,其中出现了ceres和eigen3.3版本冲突的问题,笔者在此给出了经测试可行的解决方案。
但是在编译中遇到了问题:
Could not find a package configuration file provided by "Ceres" with any of
the following names:
CeresConfig.cmake
ceres-config.cmake
Add the installation prefix of "Ceres" to CMAKE_PREFIX_PATH or set
"Ceres_DIR" to a directory containing one of the above files. If "Ceres"
provides a separate development package or SDK, be sure it has been
installed.
ceres找不到库文件,在网上查阅了相关资料后我也没有解决好这个问题,这里给出一个解决方法,大家可以试一试。https://blog.csdn.net/qq_15642411/article/details/83656855
不用这个方法的话可以往下看。
用人给的包出现错误,咱就自己下一个吧,可以去ceres的官网下载,顺便看看官网给出的案例教程。也可以直接从Github通过如下命令直接克隆:
git clone https://github.com/ceres-solver/ceres-solver
这样就把ceres项目下载到本地啦。
然后进入ceres文件夹中打开终端进行编译:
mkdir build
cd build
cmake ..
make
sudo make install
正常来说这一套命令下来,我们应该完成编译了。不过这里如果你的eigen版本是eigen3.3的话,应该会出现下面的错误:
[ 75%] Building CXX object internal/ceres/CMakeFiles/jet_test.dir/jet_test.cc.o
In file included from /usr/local/include/eigen3/Eigen/Core:348:0,
from /home/ubuntu/cartographer/ceres-solver-1.11.0/include/ceres/jet.h:165,
from /home/ubuntu/cartographer/ceres-solver-1.11.0/internal/ceres/jet_test.cc:31:
/usr/local/include/eigen3/Eigen/src/Core/util/XprHelper.h: In instantiation of ‘struct Eigen::internal::promote_scalar_arg<ceres::Jet<double, 2>, Eigen::Matrix<ceres::Jet<double, 2>, 2, 2>, false>’:
/usr/local/include/eigen3/Eigen/src/plugins/CommonCwiseBinaryOps.h:50:1: required by substitution of ‘template<class T> typename Eigen::internal::enable_if<true, const Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<typename Eigen::internal::promote_scalar_arg<ceres::Jet<double, 2>, T, Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<T, ceres::Jet<double, 2>, Eigen::internal::scalar_product_op<T, ceres::Jet<double, 2> > > >::value>::type, ceres::Jet<double, 2> >, const typename Eigen::internal::plain_constant_type<Eigen::Matrix<ceres::Jet<double, 2>, 2, 1, 0, 2, 1>, typename Eigen::internal::promote_scalar_arg<ceres::Jet<double, 2>, T, Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<T, ceres::Jet<double, 2>, Eigen::internal::scalar_product_op<T, ceres::Jet<double, 2> > > >::value>::type>::type, const Eigen::Matrix<ceres::Jet<double, 2>, 2, 1, 0, 2, 1> > >::type Eigen::operator*(const T&, const StorageBaseType&) [with T = Eigen::Matrix<ceres::Jet<double, 2>, 2, 2>]’
/home/ubuntu/cartographer/ceres-solver-1.11.0/internal/ceres/jet_test.cc:459:12: required from here
/usr/local/include/eigen3/Eigen/src/Core/util/XprHelper.h:64:8: error: no type named ‘Literal’ in ‘struct Eigen::NumTraits<ceres::Jet<double, 2> >’
struct promote_scalar_arg<S,T,false> : promote_scalar_arg_unsupported<S,T,typename NumTraits<S>::Literal> {};
^
/usr/local/include/eigen3/Eigen/src/Core/util/XprHelper.h: In instantiation of ‘struct Eigen::internal::promote_scalar_arg<ceres::Jet<double, 2>, Eigen::Matrix<ceres::Jet<double, 2>, 2, 1, 0, 2, 1>, false>’:
/usr/local/include/eigen3/Eigen/src/plugins/CommonCwiseBinaryOps.h:50:1: required by substitution of ‘template<class T> typename Eigen::internal::enable_if<true, const Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<typename Eigen::internal::traits<T>::Scalar, typename Eigen::internal::promote_scalar_arg<typename Eigen::internal::traits<T>::Scalar, T, Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<typename Eigen::internal::traits<T>::Scalar, T, Eigen::internal::scalar_product_op<typename Eigen::internal::traits<T>::Scalar, T> > >::value>::type>, const Derived, const typename Eigen::internal::plain_constant_type<Derived, typename Eigen::internal::promote_scalar_arg<typename Eigen::internal::traits<T>::Scalar, T, Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<typename Eigen::internal::traits<T>::Scalar, T, Eigen::internal::scalar_product_op<typename Eigen::internal::traits<T>::Scalar, T> > >::value>::type>::type> >::type Eigen::MatrixBase<Derived>::operator*(const T&) const [with T = T; Derived = Eigen::Matrix<ceres::Jet<double, 2>, 2, 2>] [with T = Eigen::Matrix<ceres::Jet<double, 2>, 2, 1, 0, 2, 1>]’
/home/ubuntu/cartographer/ceres-solver-1.11.0/internal/ceres/jet_test.cc:459:12: required from here
/usr/local/include/eigen3/Eigen/src/Core/util/XprHelper.h:64:8: error: no type named ‘Literal’ in ‘struct Eigen::NumTraits<ceres::Jet<double, 2> >’
/usr/local/include/eigen3/Eigen/src/Core/util/XprHelper.h: In instantiation of ‘struct Eigen::internal::promote_scalar_arg<ceres::Jet<double, 2>, Eigen::Transpose<Eigen::Matrix<ceres::Jet<double, 2>, 2, 1, 0, 2, 1> >, false>’:
/usr/local/include/eigen3/Eigen/src/plugins/CommonCwiseBinaryOps.h:50:1: required by substitution of ‘template<class T> typename Eigen::internal::enable_if<true, const Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<typename Eigen::internal::promote_scalar_arg<ceres::Jet<double, 2>, T, Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<T, ceres::Jet<double, 2>, Eigen::internal::scalar_product_op<T, ceres::Jet<double, 2> > > >::value>::type, ceres::Jet<double, 2> >, const typename Eigen::internal::plain_constant_type<Eigen::Transpose<Eigen::Matrix<ceres::Jet<double, 2>, 2, 2> >, typename Eigen::internal::promote_scalar_arg<ceres::Jet<double, 2>, T, Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<T, ceres::Jet<double, 2>, Eigen::internal::scalar_product_op<T, ceres::Jet<double, 2> > > >::value>::type>::type, const Eigen::Transpose<Eigen::Matrix<ceres::Jet<double, 2>, 2, 2> > > >::type Eigen::operator*(const T&, const StorageBaseType&) [with T = Eigen::Transpose<Eigen::Matrix<ceres::Jet<double, 2>, 2, 1, 0, 2, 1> >]’
/home/ubuntu/cartographer/ceres-solver-1.11.0/internal/ceres/jet_test.cc:460:37: required from here
/usr/local/include/eigen3/Eigen/src/Core/util/XprHelper.h:64:8: error: no type named ‘Literal’ in ‘struct Eigen::NumTraits<ceres::Jet<double, 2> >’
/usr/local/include/eigen3/Eigen/src/Core/util/XprHelper.h: In instantiation of ‘struct Eigen::internal::promote_scalar_arg<ceres::Jet<double, 2>, Eigen::Transpose<Eigen::Matrix<ceres::Jet<double, 2>, 2, 2> >, false>’:
/usr/local/include/eigen3/Eigen/src/plugins/CommonCwiseBinaryOps.h:50:1: required by substitution of ‘template<class T> typename Eigen::internal::enable_if<true, const Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<typename Eigen::internal::traits<T>::Scalar, typename Eigen::internal::promote_scalar_arg<typename Eigen::internal::traits<T>::Scalar, T, Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<typename Eigen::internal::traits<T>::Scalar, T, Eigen::internal::scalar_product_op<typename Eigen::internal::traits<T>::Scalar, T> > >::value>::type>, const Derived, const typename Eigen::internal::plain_constant_type<Derived, typename Eigen::internal::promote_scalar_arg<typename Eigen::internal::traits<T>::Scalar, T, Eigen::internal::has_ReturnType<Eigen::ScalarBinaryOpTraits<typename Eigen::internal::traits<T>::Scalar, T, Eigen::internal::scalar_product_op<typename Eigen::internal::traits<T>::Scalar, T> > >::value>::type>::type> >::type Eigen::MatrixBase<Derived>::operator*(const T&) const [with T = T; Derived = Eigen::Transpose<Eigen::Matrix<ceres::Jet<double, 2>, 2, 1, 0, 2, 1> >] [with T = Eigen::Transpose<Eigen::Matrix<ceres::Jet<double, 2>, 2, 2> >]’
/home/ubuntu/cartographer/ceres-solver-1.11.0/internal/ceres/jet_test.cc:460:37: required from here
/usr/local/include/eigen3/Eigen/src/Core/util/XprHelper.h:64:8: error: no type named ‘Literal’ in ‘struct Eigen::NumTraits<ceres::Jet<double, 2> >’
make[2]: *** [internal/ceres/CMakeFiles/jet_test.dir/jet_test.cc.o] Error 1
make[1]: *** [internal/ceres/CMakeFiles/jet_test.dir/all] Error 2
make: *** [all] Error 2
笔者看到这一堆东西也晕了,经过查阅发现,原来是eigen3.3的版本和ceres存在一些语句上的冲突,需要把eigen的版本换成eigen3.2及以下。笔者一向喜欢安装最新版本的(头铁),于是这里笔者就换的eigen3.2。
登录eigen的官网http://eigen.tuxfamily.org/index.php?title=Main_Page,可以下载一个合适的版本(这里笔者下载的是eigen3.2)。
下载解压后,还是进入解压后的文件夹,使用如下命令:
mkdir build
cd build
cmake ..
make
sudo make install
重新把eigen编译一遍。
然后,再次进入ceres文件夹,重新编译:
mkdir build
cd build
cmake ..
make
sudo make install
这次就会发现,刚才的错误没有啦,可以愉快的进行曲线拟合了。