Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to find Eigen3 with CMake

Tags:

c++

cmake

eigen3

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

like image 304
Cryoris Avatar asked Dec 07 '15 16:12

Cryoris


People also ask

How do I install Eigen Windows?

Install Eigen3 (Windows)Download the desired release from http://eigen.tuxfamily.org. Unzip in the location of your choice, preferrably at C:\ or C:\Program files for better discoverability by CMake find-modules (remember to extract the inner folder and rename it to Eigen3 or Eigen ).


2 Answers

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

  • Eigen & CMake
  • CMake: Of what use is find_package() if you need to specify CMAKE_MODULE_PATH anyway?
  • Cmake doesn't find Boost
like image 82
Florian Avatar answered Sep 21 '22 17:09

Florian


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)
like image 21
youke Avatar answered Sep 23 '22 17:09

youke