13

I am kind of desperate: For my studies I need to work with Eigen and CMake. I'm able to use Eigen if I copy the whole library in the directories where my compiler looks by default but as soon as I try to find it via
find_package(Eigen3 REQUIRED)
I get the following error:


CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
  Could NOT find Eigen3 (missing: EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK)
  (Required is at least version "2.91.0")
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  FindEigen3.cmake:76 (find_package_handle_standard_args)
  CMakeLists.txt:8 (find_package)

-- Configuring incomplete, errors occurred!


Now I searched for solutions but all I those I tried (also those available on stackoverflow:
Find package Eigen3 for CMake or CMake Can't find Eigen3 ) did not work. My Eigen Version (according to the Macros in Core/util/Macros.h) is 3.2.5. I keep the Eigen directory in /usr/local/include, I use the FindEigen3.cmake which comes with the Eigen library and my CMakeLists.txt looks as follows:


cmake_minimum_required(VERSION 2.8)
project(Test)

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})
message("Found Eigen3 in: ${EIGEN3_INCLUDE_DIR}")

add_executable(main test.cpp)

Has anyone an idea what's going wrong?

Kind regards, Julien

Community
  • 1
  • 1
Cryoris
  • 416
  • 1
  • 4
  • 12
  • 1
    Welcome to StackOverflow. The find package scripts normally use the [`find_path()`](https://cmake.org/cmake/help/v3.4/command/find_path.html) command to detect the package's include directory. If it's not found automatically you can extend [`CMAKE_INCLUDE_PATH`](https://cmake.org/cmake/help/v3.4/variable/CMAKE_INCLUDE_PATH.html) by the path where CMake should search (for example see [here](http://stackoverflow.com/questions/3808775/cmake-doesnt-find-boost)). So you could add something like `list(APPEND CMAKE_INCLUDE_PATH "/usr/local/include")` before your `find_package()` command. – Florian Dec 07 '15 at 20:46
  • Thanks! If I add the exact path to the `CMAKE_INCLUDE_PATH` it finds the package - but isn't searching manually exactly what I want to avoid? Shouldn't the `find_package()` do that for me? – Cryoris Dec 07 '15 at 21:15
  • You are right. The `CMAKE_INCLUDE_PATH` was meant for a non-standard `Eigen` installation path. I have given your code sample a try and - if I install `Eigen` into the default path - it seems to work without the need to give the path (see my answer). If you have already used the `Eigen` installation process, could you please add more details on your environment (CMake version, CMake command line call, host OS, compiler version, ...)? – Florian Dec 08 '15 at 09:48
  • Curious, is this about caffe and AI? – A P Jan 23 '17 at 10:19

2 Answers2

15

Turning my comment into an answer

The find package scripts - like FindEigen3.cmake - normally use the find_path() command to detect the package's include directory (see it's documentation for the full details).

FindEigen3.cmake uses the following code snippet:

find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library
    PATHS
    ${CMAKE_INSTALL_PREFIX}/include
    ${KDE4_INCLUDE_DIR}
    PATH_SUFFIXES eigen3 eigen
)

So it looks in CMAKE_INSTALL_PREFIX which on Unix/Linux hosts is /usr/local by default.

The following has worked for me:

  • Go to the Eigen source directory and run the CMake and installation steps

    > mkdir build
    > cd build
    > cmake ..
    > make install
    
  • Then copy - as you have done - FindEigen3.cmake to your projects source directory.

  • Now your code does find Eigen (just changed to list(APPEND ...))

    list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
    find_package(Eigen3 REQUIRED)
    

References

Community
  • 1
  • 1
Florian
  • 39,996
  • 9
  • 133
  • 149
  • Perfect it's working now! I think what also caused problems is, that I didnt use `$ make install` to install the Library but just copied it in my `/usr/local/include`. The directory `FindEigen3.cmake` was looking for was probably too deep (it was somewhere in `/usr/include/Eigen_all/eigen-tar-folder-name/`). Anyways - thank you very much for your detailed answer! – Cryoris Dec 08 '15 at 16:09
1

Add the path of FindEigen3.cmake before find_package(Eigen3 REQUIRED), like this:

LIST(APPEND CMAKE_MODULE_PATH "/usr/share/cmake-2.8/Modules/")
find_package(Eigen3)
jhoepken
  • 1,842
  • 3
  • 17
  • 24
youke
  • 11
  • 1
  • 2
    There is no needs to add `Modules/` directory, **shipped with CMake**, into `CMAKE_MODULE_PATH`: CMake searches in this directory in any case. – Tsyvarev Sep 10 '19 at 07:48