1

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:

enter image description here

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?

Community
  • 1
  • 1
Hadi GhahremanNezhad
  • 2,377
  • 5
  • 29
  • 58
  • Did you try as the error message suggests? Specifically, try appending `C:\eigen-3.3.7\cmake` to your CMake variable `CMAKE_MODULE_PATH`... – Kevin Feb 06 '20 at 21:45
  • @squareskittles where can I find CMake variable to add to it? It is not in the CMake GUI – Hadi GhahremanNezhad Feb 06 '20 at 22:01
  • The project I am talking about is [here](https://github.com/beaupreda/IMOT_OpticalFlow_Edges). – Hadi GhahremanNezhad Feb 06 '20 at 22:04
  • 1
    Just add `list(APPEND CMAKE_MODULE_PATH "C:/eigen-3.3.7/cmake")` before your call to `find_package(Eigen3 ... )` in your CMake code. – Kevin Feb 06 '20 at 22:19
  • @squareskittles: Variable `CMAKE_MODULE_PATH` helps only in finding `FindXXX.cmake` scripts, but doesn't help in finding `XXXConfig.cmake` scripts, on of which is probably located under `C:/eigen-3.3.7/cmake` directory. See [that my answer](https://stackoverflow.com/a/60011171/3440745). – Tsyvarev Feb 06 '20 at 22:23
  • @Tsyvarev The `FindEigen3.cmake` file does appear to be present in the Eigen3 repo [here](https://github.com/libigl/eigen/blob/master/cmake/FindEigen3.cmake). I thought, if available, the `FindXXX.cmake` should be the first choice in general? – Kevin Feb 06 '20 at 22:27
  • @squareskittles: `FindEigen3.cmake` is present in the Eigen3 repo, but it is not **installed**: `FindXXX.cmake` script is not normally installed with the project XXX, such files are needed to be shipped with the project which **uses** XXX. Instead, `Eigen3Config.cmake` is configured and installed with Eigen3, and `C:/eigen-3.3.7` looks like installation directory for that project. – Tsyvarev Feb 06 '20 at 22:32
  • @HadiGhahremanNezhad: The line `... set "Eigen3_DIR" to a directory containing one of the above files.` in the error message means that you may set `Eigen3_DIR` variable (it is the first on the screenshot you show us) to the directory, which contains `Eigen3Config.cmake` file. – Tsyvarev Feb 06 '20 at 22:34
  • @squareskittles adding `list(APPEND CMAKE_MODULE_PATH "C:/eigen-3.3.7/cmake")` before `find_package(Eigen3 ... )` made the error go away. I still am facing errors in building the project in Visual Studio though. – Hadi GhahremanNezhad Feb 06 '20 at 22:35
  • @Tsyvarev Yes, I did as you say, but when configuring CMake the entered address goes away and the same error appears again. – Hadi GhahremanNezhad Feb 06 '20 at 22:36
  • So you **have** the file `C:/eigen-3.3.7/cmake/Eigen3Config.cmake`, but setting `Eigen3_DIR` variable to `C:/eigen-3.3.7/cmake` doesn't help, am I correctly understand your situation? – Tsyvarev Feb 06 '20 at 22:40
  • @Tsyvarev Yes, that's correct. Thank you for the clarification. It is so often difficult to distinguish which approach is more suitable, given provided information. I suppose that is what comments are for. :) – Kevin Feb 06 '20 at 22:45
  • 3
    If Eigen was "*downloaded and extracted*", perhaps from Github, it would seem the installation step was skipped. So, the package configuration file may still be in its un-configured form: `cmake/Eigen3Config.cmake.in` – Kevin Feb 06 '20 at 22:49
  • 1
    @squareskittles: Yes, it is very seems to be so. If setting `CMAKE_MODULE_PATH` helps in locating the script, then this is `FindEigen3.cmake` script which is located under given directory. So the content of the directory is like [this](https://github.com/libigl/eigen/tree/master/cmake), and it contains `Eigen3Config.cmake.in` file, not the `Eigen3Config.cmake` one. – Tsyvarev Feb 06 '20 at 22:52
  • @squareskittles [Here](https://eigen.tuxfamily.org/dox/GettingStarted.html) it says there is no need to install. @Tsyvarev you are right. `Eigen3Config.cmake.in` is in the directory not `Eigen3Config.cmake`. – Hadi GhahremanNezhad Feb 06 '20 at 23:08

2 Answers2

5

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")
Kevin
  • 16,549
  • 8
  • 60
  • 74
1

I faced the same problem today, my solution is

  1. Install eigen.
cd path/to/eigen3.X.X (where you can find CMakeLists.txt)
mkdir build
cd build
rm ../CMakeCache.txt (only if there is one.)
cmake ..
cmake --build . --target install
  1. set Eigen3_DIR to path/to/where/Eigen3Config.cmake/is

On windows that may be: C:\Program Files (x86)\Eigen3\share\eigen3\cmake

Reference for cmake projects using eigen3:

https://eigen.tuxfamily.org/dox/TopicCMakeGuide.html

Ted Lin
  • 11
  • 3