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,
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
参考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 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,该程序用于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,发现顺利编译