ubuntu安装ceres、pyceres及对应报错解决

一、安装流程

ceres安装官方教程
ceres_python_bindings/pyceres是使用pybind11将ceres转化为Python形式
ceres_python_bindings

git clone https://ceres-solver.googlesource.com/ceres-solver
cd ceres-solver

#如果需要安装pyceres,则需要加以下步骤
git clone https://github.com/Edwinem/ceres_python_bindings
cp ../custom_cpp_cost_functions.cpp ceres_python_bindings/python_bindings/custom_cpp_cost_functions.cpp
cd ceres_python_bindings
git submodule init
git submodule update
cd ..
echo "include(ceres_python_bindings/AddToCeres.cmake)" >> CMakeLists.txt

mkdir ceres-bin
cd ceres-bin
cmake ..
make -j8
make test

二、报错解决

安装ceres时会出现很多问题,在这里做一下简略的记录
首先一定要确认安装的gcc、cmake、eigen是否满足ceres要求,否则会花费很多精力修改对应版本!

Ceres Solver 2.2 requires a fully C++17-compliant compiler.
CMake 3.10 or later required.
Eigen 3.3 or later required.
glog 0.3.5 or later. Recommended
SuiteSparse 4.5.6 or later.

1、std报错

/ceres-solver/include/ceres/internal/integer_sequence_algorithm.h:75:31: error: 'integer_sequence' is not a member of 'std'
   75 |                          std::integer_sequence<T, N, Ns...>,

std应该是c++版本的问题,查issue发现有一条对应的:

You are not compiling your application with a C++ standard >= 14 which is what the master branch of Ceres requires. I assume you are not using CMake to build your application either, as if you were the Ceres target would capture this dependency.

使用man gcc指令查看,发现其中支持c++14,查看cmake版本也满足要求。证明本机配置条件已经满足,修改cmakelists,指定C++版本

set(CMAKE_CXX_STANDARD 14)
# set(CMAKE_CXX_FLAGS "-std=c++14")

2、报错eigen问题

In file included from /usr/local/include/Eigen/Core:164,
from /home/zhouxin/DYT/code/Equivariant-SFM/bundle_adjustment/ceres-solver/include/ceres/internal/eigen.h:34,
from /home/zhouxin/DYT/code/Equivariant-SFM/bundle_adjustment/ceres-solver/internal/ceres/block_random_access_dense_matrix.cc:34:
/usr/local/include/Eigen/src/Core/util/Memory.h: In function 'void* Eigen::internal::handmade_aligned_malloc(std::size_t, std::size_t)':
/usr/local/include/Eigen/src/Core/util/Memory.h:107:30: error: suggest parentheses around '-' in operand of '&' [-Werror=parentheses]

切换gcc版本 gcc多版本切换

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 35
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 35

更换eigen版本,首先删除本地eigen,然后从官网找到对应想要的版本并安装

locate eigen3
rm -rf /usr/local/share/pkgconfig/eigen3.pc /usr/local/share/eigen3 /usr/local/include/eigen3 
git clone https://gitlab.com/libeigen/eigen.git
cd eigen
mkbir build
cd build
cmake ..
make
sudo make install
sudo cp -r /usr/local/include/eigen3/Eigen /usr/local/include 
cat /usr/local/include/eigen3/Eigen/src/Core/util/Macros.h

3、未定义的引用,发现libm和libc版本不同

/lib/x86_64-linux-gnu/libm.so.6:对‘__strtof128_nan@GLIBC_PRIVATE’未定义的引用
collect2: error: ld returned 1 exit status
examples/CMakeFiles/helloworld_analytic_diff.dir/build.make:113: recipe for target 'bin/helloworld_analytic_diff' failed
make[2]: *** [bin/helloworld_analytic_diff] Error 1
CMakeFiles/Makefile2:340: recipe for target 'examples/CMakeFiles/helloworld_analytic_diff.dir/all' failed
make[1]: *** [examples/CMakeFiles/helloworld_analytic_diff.dir/all] Error 2
make[1]: *** 正在等待未完成的任务....
[ 87%] Linking CXX executable ../bin/helloworld_numeric_diff
/lib/x86_64-linux-gnu/libm.so.6:对‘__strtof128_nan@GLIBC_PRIVATE’未定义的引用
collect2: error: ld returned 1 exit status
examples/CMakeFiles/helloworld.dir/build.make:113: recipe for target 'bin/helloworld' failed
make[2]: *** [bin/helloworld] Error 1
CMakeFiles/Makefile2:288: recipe for target 'examples/CMakeFiles/helloworld.dir/all' failed
make[1]: *** [examples/CMakeFiles/helloworld.dir/all] Error 2
/lib/x86_64-linux-gnu/libm.so.6:对‘__strtof128_nan@GLIBC_PRIVATE’未定义的引用
collect2: error: ld returned 1 exit status
examples/CMakeFiles/helloworld_numeric_diff.dir/build.make:113: recipe for target 'bin/helloworld_numeric_diff' failed
make[2]: *** [bin/helloworld_numeric_diff] Error 1
CMakeFiles/Makefile2:314: recipe for target 'examples/CMakeFiles/helloworld_numeric_diff.dir/all' failed
make[1]: *** [examples/CMakeFiles/helloworld_numeric_diff.dir/all] Error 2
Makefile:145: recipe for target 'all' failed
make: *** [all] Error 2

首先查看对应版本,发现版本不对应,备份后修改

ll /lib/x86_64-linux-gnu
man ln
sudo cp libm.so.6 libm.so.61
sudo rm libm.so.6
ln -s  libm-2.23.so libm.so.6

[注意]:此处必须先行查看自己所配备的版本,因为我的系统里之前安装的就是libm.so.6和libc.so.6,只是后续由于误操作又安装并指配了libm-2.23.so,所以需要重新指定。如果自己是其他版本的,只需要根据自己电脑版本进行设置即可。

参考1
参考2

4、c++: fatal error: 已杀死 signal terminated program cc1plus

compilation terminated.
internal/ceres/CMakeFiles/ceres_internal.dir/build.make:579: recipe for target 'internal/ceres/CMakeFiles/ceres_internal.dir/generated/schur_eliminator_2_4_d.cc.o' failed
make[2]: *** [internal/ceres/CMakeFiles/ceres_internal.dir/generated/schur_eliminator_2_4_d.cc.o] Error 1
make[2]: *** 正在等待未完成的任务....
c++: fatal error: 已杀死 signal terminated program cc1plus

设置swap

swap设置方法

5、使用ceres_python_bindings报错1— ‘ceres::Problem::Problem(const ceres::Problem&)’ is private,该程序用于ceres python编译

python_module.cpp:63:26: error: ‘ceres::Problem::Problem(const ceres::Problem&)’ is private within this context
return ceres::Problem(o);

查issue发现有一条对应的,作者回复

It was developed with the latest version of Ceres on github.
I also tried with 1.14 and got the same errors. So that version is just too old.

所以升级对应版本

6、使用ceres_python_bindings报错2—LocalParameterization’ is not a member of ‘ceres’,该程序用于ceres python编译

error: 'LocalParameterization' is not a member of 'ceres'
  199 |         ceres::LocalParameterization, /* Parent class */

看到issue上有人提问相同问题作者没有回复,怀疑可能是ceres 2.1.0版本太新ceres_python_bindings无法适配(由发布日期看出,ceres 2.1.0新版本推出pyceres也没有做出相应版本更新),改成ceres2.0.0,发现顺利编译。

**[注意]**重新安装ceres2.0.0即先卸载之前版本,之后再按照官方教程依次下载安装ceres2.0.0,不需要再重新安装cmake等工具。
卸载ceres需要删除"/usr/local/lib/“中的库文件以及”/usr/local/include/ceres/"中的头文件:

sudo rm -r /usr/local/lib/cmake/Ceres
sudo rm -rf /usr/local/include/ceres /usr/local/lib/libceres.a
  • 7
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值