Issue
I am trying to build a project with CMake on Windows 10. But I keep getting this error for hours:
Error:
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.
I downloaded Eigen, extracted it, and added a new Environment variable called EIGEN3_INCLUDE_DIR
with value C:\eigen-3.3.7\cmake
. Also, I added a line to the CMake file of the project which now looks like this:
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:
I also copied the FindEigen3.cmake
file in my current project.
But I am still getting the same error over and over again. Is there a way to fix this?
Solution
To summarize the comments for completeness:
CMake's find_package()
command has two modes of operation: Module and Config mode. This error essentially says Module mode failed, then Config mode failed to find the Eigen3 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.
In general, when a package XXX (such as Eigen3, for example) is installed, that package should configure the XXXConfig.cmake
file. That way, external projects can find and use package XXX by calling find_package()
in Config mode.
Because your Eigen3 package was not installed, the Eigen3Config.cmake
file did not get configured. Thus, the Module mode search should work for you, as only the FindEigen3.cmake
file exists in your Eigen3 directories. For Module mode, the path to the FindEigen3.cmake
file must be added to the CMAKE_MODULE_PATH
, as the error suggests. Adding this line before the find_package(Eigen3 ...)
call allows CMake Module mode to succeed:
list(APPEND CMAKE_MODULE_PATH "C:/eigen-3.3.7/cmake")
Answered By - Kevin Answer Checked By - Marilyn (WPSolving Volunteer)