ubuntu22.04 安装ceres踩坑指南(含省力有效安装方法)
ubuntu22.04 安装ceres踩坑指南(含省力有效安装方法)
以下是报错复现,直到下一个小标题为止。
编译打符项目时,报错:
CMake Error at CMakeLists.txt:27 (find_package):
By not providing "FindCeres.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "Ceres", but
CMake did not find one.
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
我的解决步骤:
sudo apt-get update
sudo apt-get install cmake libgoogle-glog-dev libgflags-dev libeigen3-dev libsuitesparse-dev liblapack-dev libtbb-dev
git clone https://github.com/ceres-solver/ceres-solver
cd ceres-solver
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/ceres ..
make -j8
sudo make install
在执行
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local/ceres ..
时报错:
CMake Error at CMakeLists.txt:173 (find_package):
By not providing "Findabsl.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "absl", but
CMake did not find one.
Could not find a package configuration file provided by "absl" with any of
the following names:
abslConfig.cmake
absl-config.cmake
Add the installation prefix of "absl" to CMAKE_PREFIX_PATH or set
"absl_DIR" to a directory containing one of the above files. If "absl"
provides a separate development package or SDK, be sure it has been
installed.
看样子是缺少abseil库,于是继续手动编译安装:
git clone https://github.com/abseil/abseil-cpp
cd abseil-cpp
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/absl .. # 指定安装路径
make -j8
sudo make install
很顺利,没什么问题,于是回到ceres-solver,编译,报错:
zhizhi@zzpc:~/ceres-solver/build$ cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr/local/ceres \
-Dabsl_DIR=/usr/local/absl/lib/cmake/absl
CMake Error at internal/ceres/CMakeLists.txt:371 (add_library):
Target "test_util" links to target "GTest::gmock" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
CMake Error at internal/ceres/CMakeLists.txt:385 (add_executable):
Target "array_utils_test" links to target "GTest::gmock" but the target was
not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?
Call Stack (most recent call first):
internal/ceres/CMakeLists.txt:414 (ceres_test)
CMake Error at internal/ceres/CMakeLists.txt:385 (add_executable):
Target "array_utils_test" links to target "GTest::gmock_main" but the
target was not found. Perhaps a find_package() call is missing for an
IMPORTED target, or an ALIAS target is missing?
Call Stack (most recent call first):
# ……
通过
ls /usr/local/lib | grep libgtest
ls /usr/local/lib | grep libgmock
ls /usr/local/include | grep gtest
ls /usr/local/include | grep gmock
解决,然后make -j4
/home/zhizhi/ceres-solver/internal/ceres/test_util.cc:136:30: error: ‘SrcDir’ is not a member of ‘testing’
136 | return JoinPath(::testing::SrcDir() + CERES_TEST_SRCDIR_SUFFIX, filename);
| ^~~~~~
以上都是踩坑部分,可以思考一下,但别这样照着做了。以下是省力有效版安装方法。
出现如上报错大概率是因为cuda导致报错。这里选择回退版本
点这里下载官网的ceres2.1.0
如果报错
file STRINGS file "/usr/include/tbb/tbb_stddef.h" cannot be read.
可以把
tbb_stddef.h的内容放进去:
cd /usr/include/tbb
sudo touch tbb_stddef.h
sudo gedit tbb_stddef.h
然后
cmake ..
make -j4
sudo make install
成功。