cmake Ceres 配置错误:Found Eigen dependency, but the version of Eigen found () does not exactly match the version of Eigen Ceres was compiled with (3.4.0)

Ceres 编译错误: Found Eigen dependency, but the version of Eigen found () does not exactly match the version of Eigen Ceres was compiled with (3.4.0)

博主在学习高博的《视觉SLAM14讲》时 cmake 配置过程中遇到了以下问题:

Fig.1 Found Eigen dependency, but the version of Eigen found () does not exactly match the version of Eigen Ceres was compiled with (3.4.0)
Fig.1 cmake错误

查看 cmake 的 Ceres 配置文件 /usr/local/lib/cmake/Ceres/CeresConfig.cmake 处与 Eigen 有关的部分

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
206 # Eigen.
207 # Flag set during configuration and build of Ceres.
208 set(CERES_EIGEN_VERSION 3.4.0)
209 # Search quietly to control the timing of the error message if not found. The
210 # search should be for an exact match, but for usability reasons do a soft
211 # match and reject with an explanation below.
212 find_package(Eigen3 ${CERES_EIGEN_VERSION} QUIET)
213 if (Eigen3_FOUND)
214 if (NOT Eigen3_VERSION VERSION_EQUAL CERES_EIGEN_VERSION)
215 # CMake's VERSION check in FIND_PACKAGE() will accept any version >= the
216 # specified version. However, only version = is supported. Improve
217 # usability by explaining why we don't accept non-exact version matching.
218 ceres_report_not_found("Found Eigen dependency, but the version of Eigen "
219 "found (${Eigen3_VERSION}) does not exactly match the version of Eigen "
220 "Ceres was compiled with (${CERES_EIGEN_VERSION}). This can cause subtle "
221 "bugs by triggering violations of the One Definition Rule. See the "
222 "Wikipedia article http://en.wikipedia.org/wiki/One_Definition_Rule "
223 "for more details")
224 endif ()
...

发现可能是此处 Eigen3_VERSION 这一与 Eigen 版本相关的变量并没有定义,于是尝试对配置文件添加以下内容进行修改

1
2
3
4
5
6
7
8
9
if(EIGEN3_VERSION)
set(Eigen3_VERSION ${EIGEN3_VERSION})
set(Eigen3_DIR ${EIGEN3_INCLUDE_DIR})
elseif(Eigen_VERSION)
set(Eigen3_VERSION ${Eigen_VERSION})
set(Eigen3_DIR ${Eigen_INCLUDE_DIR})
elseif(EIGEN_VERSION)
set(Eigen3_VERSION ${EIGEN_VERSION})
set(Eigen3_DIR ${EIGEN_INCLUDE_DIR})
Fig.2 修改配置文件
Fig.2 修改配置文件

即可成功进行 cmake 配置。

Reference


cmake Ceres 配置错误:Found Eigen dependency, but the version of Eigen found () does not exactly match the version of Eigen Ceres was compiled with (3.4.0)
https://blog.iks-ran.com/2025/05/01/ceres_eigen_version_error/
Author
iks-ran
Posted on
May 1, 2025
Licensed under