无法找到Eigen3与CMake [英] Unable to find Eigen3 with CMake

查看:8113
本文介绍了无法找到Eigen3与CMake的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点绝望:
对于我的研究,我需要与Eigen和CMake一起工作。我可以使用Eigen如果我复制整个库在我的编译器看起来默认的目录,但一旦我试图找到它通过

find_package(Eigen3 REQUIRED)

我收到以下错误:

  
CMake错误在/ usr / share /模块/ FindPackageHandleStandardArgs.cmake:148(消息):
无法找到Eigen3(缺少:EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK)
(必须至少是版本2.91.0)
调用堆栈调用第一个):
/usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:388(_FPHSA_FAILURE_MESSAGE)
FindEigen3.cmake:76(find_package_handle_standard_args)
CMakeLists.txt:8(find_package)



- 配置不完整,发生错误!




现在我搜索解决方案,但我所有的那些在stackoverflow上可用:

查找包Eigen3 for CMake

CMake找不到Eigen3
没有工作。
我的特征版本(根据 Core / util / Macros.h 中的宏)是3.2.5。
我保留Eigen目录在 / usr / local / include ,我使用 FindEigen3.cmake 带有Eigen库,我的 CMakeLists.txt 如下所示:

  
cmake_minimum_required(VERSION 2.8)
project(Test)

set(CMAKE_MODULE_PATH $ {CMAKE_CURRENT_SOURCE_DIR})
find_package(Eigen3 REQUIRED)
包含目录($ {EIGEN3_INCLUDE_DIR})
消息(Found Eigen3 in:$ {EIGEN3_INCLUDE_DIR})

add_executable(main test.cpp)



有人知道发生了什么问题吗?



亲爱的,
Julien

解决方案

将我的评论转换为答案



find包脚本 - 如 FindEigen3.cmake - 通常使用 find_path()命令来检测包的include目录(有关完整详情,请参见文档)。

FindEigen3.cmake 使用以下代码片段:


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


=https://cmake.org/cmake/help/v3.4/variable/CMAKE_INSTALL_PREFIX.html =nofollow> CMAKE_INSTALL_PREFIX 其中默认情况下,Unix / Linux主机为 / usr / local



>


  • 转到 Eigen 源目录并运行CMake和安装步骤



     > mkdir build 
    > cd build
    > cmake ..
    > make install


  • 然后复制 - 如你所做 - FindEigen3。 cmake 到您的项目源目录。


  • 现在您的代码确实找到 Eigen (只是更改为 ...)

     列表(APPEND CMAKE_MODULE_PATH$ {CMAKE_CURRENT_SOURCE_DIR})
    find_package(Eigen3 REQUIRED)




参考




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

解决方案

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

这篇关于无法找到Eigen3与CMake的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆