CMake发现本征不正确的结果 [英] CMake find eigen incorrect results
问题描述
我正在尝试使用CMake使用 Eigen
编译代码段,但是CMake似乎很难找到正确的路径,即使源代码在那里.
I am trying to compile a code snippet with Eigen
using CMake, but CMake seems to have trouble finding the correct path, even if the source code is there.
这是我的 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
中导入标头的方式:
This is how I import headers in 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
下,这是目录结构:
My Eigen
is installed under /usr/include/eigen3
, here is the directory structure:
yuqiong@yuqiong-G7-7588:/usr/include/eigen3$ ls
Eigen signature_of_eigen3_matrix_library unsupported
因此,本征库的正确路径是/usr/include/eigen3/Eigen
.
So the correct path to Eigen library is /usr/include/eigen3/Eigen
.
但是,当我运行上述 CMakeLists.txt
文件的 cmake ..
然后 make
时,使用 -LH
标志,CMake抱怨找不到 igen .这是它认为 Eigen
所在位置的路径:
However, when I run cmake ..
and then make
for the aforementioned CMakeLists.txt
file, with the -LH
flag, CMake complains it can't find Eigen
. This is the path it thinks where Eigen
is:
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所在的文件夹的结构:
This is the structure of the folder where it think Eigen is:
yuqiong@yuqiong-G7-7588:/usr/local/share/eigen3$ tree
.
└── cmake
├── Eigen3Config.cmake
├── Eigen3ConfigVersion.cmake
├── Eigen3Targets.cmake
└── UseEigen3.cmake
我很困惑,为什么CMake会有这种行为?在这种情况下,我如何让它找到 Eigen
的正确路径?
I am confused why CMake has such behavior? How can I let it find the correct path of Eigen
in this case?
所有这些环境设置都很难使它正确...
All this environment set-ups are so tricky to get it right...
推荐答案
感谢上面的评论.我认为问题可能出在 Eigen
团队在不同版本之间以某种方式更改了目录结构,而旧的include路径不再起作用.
Thanks for the comments above. I think the issue might be the Eigen
team changed their directory structure somehow between different versions, and the old include path does not work anymore.
对我来说,解决方案是将 #include< Eigen/Dense>
更改为 #include< eigen3/Eigen/Dense>
.之后, g ++
和 CMake
可以找到路径.
The solution for me was to change #include <Eigen/Dense>
to #include <eigen3/Eigen/Dense>
. After that g++
and CMake
can find the path.
我确实按照此官方文档安装了 Eigen
.,这就是为什么令我惊讶的是安装仍然存在问题的原因.
I did install Eigen
following this official doc, which was why I was surprised the installation is still problematic.
此答案解决了我的问题.
This answer solved my problem.
此答案也解决了该问题.
This answer also solves the problem.
另一方面,我的CMake文件有些混乱,包含了 include_directories
和 target_link_libraries
.
On another note, my CMake file was a bit messed up, with both include_directories
and target_link_libraries
.
这篇关于CMake发现本征不正确的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!