CMake-Eigen3_DIR-NOTFOUND

CMake - Eigen3_DIR-NOTFOUND

我正在尝试在 Windows 10 上使用 CMake 构建一个项目。但几个小时以来我一直收到此错误:

错误:

  CMake Error at of_dis/CMakeLists.txt:8 (FIND_PACKAGE):
  By not providing "FindEigen3.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Eigen3", but
  CMake did not find one.

  Could not find a package configuration file provided by "Eigen3" with any
  of the following names:

    Eigen3Config.cmake
    eigen3-config.cmake

  Add the installation prefix of "Eigen3" to CMAKE_PREFIX_PATH or set
  "Eigen3_DIR" to a directory containing one of the above files.  If "Eigen3"
  provides a separate development package or SDK, be sure it has been
  installed.

我下载了 Eigen,将其解压缩,并添加了一个名为 EIGEN3_INCLUDE_DIR 的新环境变量,其值为 C:\eigen-3.3.7\cmake。另外,我在项目的 CMake 文件中添加了一行,现在看起来像这样:

CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)

project(IMOT_OpticalFlow_Edges)

find_package(OpenCV REQUIRED)

add_subdirectory(of_dis)

include_directories(./of_dis ${OpenCV_INCLUDE_DIRS})
INCLUDE_DIRECTORIES ( "$ENV{EIGEN3_INCLUDE_DIR}" )

set(CMAKE_CXX_STANDARD 11)

#set(OpenCV_DIR "C:/opencv/opencv3.4.1/opencv-3.4.1/build/install")
set(OpenCV_DIR "C:/opencv/opencv3.4.1/opencv-3.4.1/build/install/x64/vc14/lib")

set(SOURCE_FILES src/main.cpp src/support/Place.cpp src/support/Line.cpp src/support/Argument.cpp
    src/support/FileOperations.cpp src/frame_processing/FrameProcessor.cpp src/flow_processing/FlowProcessor.cpp
    src/edge_processing/EdgeProcessor.cpp src/detection/Detector.cpp)

add_executable(IMOT_OpticalFlow_Edges ${SOURCE_FILES})

target_link_libraries(IMOT_OpticalFlow_Edges ${OpenCV_LIBS})

CMake GUI:

我还在当前项目中复制了FindEigen3.cmake文件。 但是我仍然一遍又一遍地遇到同样的错误。有办法解决这个问题吗?

总结评论的完整性:

CMake的find_package()命令有两种运行模式:ModuleConfig模式。这个错误本质上说 Module 模式失败,然后 Config 模式找不到 Eigen3 包:

  By not providing "FindEigen3.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Eigen3", but
  CMake did not find one.

  Could not find a package configuration file provided by "Eigen3" with any
  of the following names:

    Eigen3Config.cmake
    eigen3-config.cmake

  Add the installation prefix of "Eigen3" to CMAKE_PREFIX_PATH or set
  "Eigen3_DIR" to a directory containing one of the above files.  If "Eigen3"
  provides a separate development package or SDK, be sure it has been
  installed.

一般情况下,安装包XXX(例如Eigen3)时,该包应该配置XXXConfig.cmake文件。这样,外部项目可以通过在 Config 模式下调用 find_package() 来找到并使用包 XXX。

因为您的 Eigen3 软件包未安装Eigen3Config.cmake 文件未配置。因此,Module 模式搜索应该适合您,因为您的 Eigen3 目录中只存在 FindEigen3.cmake 文件。对于 Module 模式,FindEigen3.cmake 文件的路径必须添加到 CMAKE_MODULE_PATH,如错误提示的那样。在 find_package(Eigen3 ...) 调用之前添加此行允许 CMake Module 模式成功:

list(APPEND CMAKE_MODULE_PATH "C:/eigen-3.3.7/cmake")