无法使用 CMake 找到 Eigen3

Unable to find Eigen3 with CMake(无法使用 CMake 找到 Eigen3)

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

问题描述

我有点绝望:对于我的学习,我需要使用 Eigen 和 CMake.如果我将整个库复制到编译器默认查找的目录中,但一旦我尝试通过
找到它,我就可以使用 Eigenfind_package(Eigen3 REQUIRED)
我收到以下错误:

<代码>/usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake 处的 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上可用的:
查找 CMake 的 Eigen3 包或者CMake 找不到 Eigen3 )不工作.我的特征版本(根据 Core/util/Macros.h 中的宏)是 3.2.5.我将 Eigen 目录保存在 /usr/local/include 中,我使用了 Eigen 库附带的 FindEigen3.cmake 和我的 CMakeLists.txt> 看起来如下:

<代码>cmake_minimum_required(版本 2.8)项目(测试)设置(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})find_package(需要Eigen3)包含目录(${EIGEN3_INCLUDE_DIR})message("在:${EIGEN3_INCLUDE_DIR} 中找到 Eigen3")add_executable(主测试.cpp)

有人知道出了什么问题吗?

亲切的问候,朱利安

解决方案

将我的评论转化为答案

查找包脚本 - 如 FindEigen3.cmake - 通常使用 find_path() 命令来检测包的包含目录(请参阅 它的文档 了解完整细节).

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

<块引用>

find_path(EIGEN3_INCLUDE_DIR NAMES signature_of_eigen3_matrix_library路径${CMAKE_INSTALL_PREFIX}/包含${KDE4_INCLUDE_DIR}PATH_SUFFIXES eigen3 特征)

所以它看起来在 CMAKE_INSTALL_PREFIX 在 Unix/Linux 主机上默认为 /usr/local.

以下对我有用:

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

    >mkdir 构建>光盘构建>cmake ..>进行安装

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

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

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

参考资料

  • Eigen &CMake
  • CMake:如果您仍然需要指定 CMAKE_MODULE_PATH,那么 find_package() 有什么用?
  • Cmake 没有找到 Boost

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

  • Eigen & CMake
  • CMake: Of what use is find_package() if you need to specify CMAKE_MODULE_PATH anyway?
  • Cmake doesn't find Boost

这篇关于无法使用 CMake 找到 Eigen3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:无法使用 CMake 找到 Eigen3

基础教程推荐