CMake 查找特征不正确的结果

CMake find eigen incorrect results

本文关键字:结果 不正确 特征 查找 CMake      更新时间:2023-10-16

我正在尝试使用 CMake 编译带有Eigen的代码片段,但 CMake 似乎很难找到正确的路径,即使源代码在那里。

这是我CMakeLists.txt文件。

cmake_minimum_required(VERSION 3.14.2)
project(test)
# set default build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

find_package(OpenCV 3 REQUIRED)
find_package (Eigen3 3.3 REQUIRED NO_MODULE)
include_directories(
include
${OpenCV_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIR}
)

add_executable(playground playground.cpp)
target_link_libraries(playground ${OpenCV_LIBS} Eigen3::Eigen)

这就是我在playground.cpp中导入标头的方式:

#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <string>
#include <Eigen>

我的Eigen安装在/usr/include/eigen3下,这是目录结构:

yuqiong@yuqiong-G7-7588:/usr/include/eigen3$ ls
Eigen  signature_of_eigen3_matrix_library  unsupported

所以通往特征库的正确路径是/usr/include/eigen3/Eigen

但是,当我运行cmake ..然后make上述CMakeLists.txt文件时,带有-LH标志,CMake 抱怨它找不到Eigen。这是它认为Eigen所在的路径:

yuqiong@yuqiong-G7-7588:/media/yuqiong/DATA/vignetting/catkin_ws/src/vig2/src/build$ cmake -LH ..
-- Configuring done
-- Generating done
-- Build files have been written to: /media/yuqiong/DATA/vignetting/catkin_ws/src/vig2/src/build
-- Cache values
// Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel ...
CMAKE_BUILD_TYPE:STRING=
// Install path prefix, prepended onto install directories.
CMAKE_INSTALL_PREFIX:PATH=/usr/local
// The directory containing a CMake configuration file for Eigen3.
Eigen3_DIR:PATH=/usr/local/share/eigen3/cmake
// The directory containing a CMake configuration file for OpenCV.
OpenCV_DIR:PATH=/opt/ros/kinetic/share/OpenCV-3.3.1-dev

这是它认为 Eigen 所在的文件夹的结构:

yuqiong@yuqiong-G7-7588:/usr/local/share/eigen3$ tree
.
└── cmake
├── Eigen3Config.cmake
├── Eigen3ConfigVersion.cmake
├── Eigen3Targets.cmake
└── UseEigen3.cmake

我很困惑为什么CMake会有这样的行为?在这种情况下,我怎样才能让它找到正确的Eigen路径?

所有这些环境设置都非常棘手,无法正确处理......

感谢您上面的评论。我认为问题可能是Eigen团队在不同版本之间以某种方式更改了目录结构,并且旧的包含路径不再起作用。

我的解决方案是将#include <Eigen/Dense>更改为#include <eigen3/Eigen/Dense>。之后,g++CMake可以找到路径。

我确实按照这个官方文档安装了Eigen,这就是为什么我对安装仍然有问题感到惊讶的原因。

这个答案解决了我的问题。

这个答案也解决了问题。

另一方面,我的CMake文件有点混乱,既有include_directories又有target_link_libraries