我正在尝试在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
value 的新环境变量C:\eigen-3.3.7\cmake
。另外,我在项目的CMake文件中添加了一行,现在看起来像这样:
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})
我还在FindEigen3.cmake
当前项目中复制了该文件。但是我仍然一遍又一遍地遇到同样的错误。有没有办法来解决这个问题?
总结评论的完整性:
CMake的find_package()
命令具有两种操作模式:模块和配置模式。此错误从本质上说是模块模式失败,然后配置模式无法找到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
文件。这样,外部项目可以通过find_package()
在Config模式下调用来查找和使用软件包XXX 。
由于未安装您的Eigen3软件包,Eigen3Config.cmake
因此未配置文件。因此,模块模式搜索应该适合您,因为FindEigen3.cmake
Eigen3目录中仅存在该文件。对于模块模式,FindEigen3.cmake
必须将文件路径添加到中CMAKE_MODULE_PATH
,如错误所示。在find_package(Eigen3 ...)
调用之前添加此行可允许CMake 模块模式成功:
list(APPEND CMAKE_MODULE_PATH "C:/eigen-3.3.7/cmake")