Unable to find Eigen3 with CMake

后端 未结 2 741
星月不相逢
星月不相逢 2020-12-11 15:57

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

相关标签:
2条回答
  • 2020-12-11 16:22

    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
    0 讨论(0)
  • 2020-12-11 16:43

    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)
    
    0 讨论(0)
提交回复
热议问题