CMake - Eigen3_DIR-NOTFOUND

Had*_*had 1 cmake eigen3

我正在尝试在 Windows 10 上使用 CMake 构建一个项目。但是我几个小时一直收到这个错误:

错误:

  CMake Error at of_dis/CMakeLists.txt:8 (FIND_PACKAGE):
  By not providing "FindEigen3.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Eigen3", but
  CMake did not find one.

  Could not find a package configuration file provided by "Eigen3" with any
  of the following names:

    Eigen3Config.cmake
    eigen3-config.cmake

  Add the installation prefix of "Eigen3" to CMAKE_PREFIX_PATH or set
  "Eigen3_DIR" to a directory containing one of the above files.  If "Eigen3"
  provides a separate development package or SDK, be sure it has been
  installed.
Run Code Online (Sandbox Code Playgroud)

我下载了 Eigen,提取了它,并添加了一个名为EIGEN3_INCLUDE_DIRvalue的新环境变量C:\eigen-3.3.7\cmake。另外,我在项目的 CMake 文件中添加了一行,现在看起来像这样:

CMakeLists.txt:

  CMake Error at of_dis/CMakeLists.txt:8 (FIND_PACKAGE):
  By not providing "FindEigen3.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Eigen3", but
  CMake did not find one.

  Could not find a package configuration file provided by "Eigen3" with any
  of the following names:

    Eigen3Config.cmake
    eigen3-config.cmake

  Add the installation prefix of "Eigen3" to CMAKE_PREFIX_PATH or set
  "Eigen3_DIR" to a directory containing one of the above files.  If "Eigen3"
  provides a separate development package or SDK, be sure it has been
  installed.
Run Code Online (Sandbox Code Playgroud)

CMake图形用户界面:

在此处输入图片说明

我还在FindEigen3.cmake当前项目中复制了该文件。但我仍然一遍又一遍地得到同样的错误。有没有办法来解决这个问题?

squ*_*les 5

为了完整性总结评论:

CMake的find_package()命令有两种操作模式:Module模式Config模式。此错误本质上表示模块模式失败,然后配置模式无法找到 Eigen3 包:

  By not providing "FindEigen3.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Eigen3", but
  CMake did not find one.

  Could not find a package configuration file provided by "Eigen3" with any
  of the following names:

    Eigen3Config.cmake
    eigen3-config.cmake

  Add the installation prefix of "Eigen3" to CMAKE_PREFIX_PATH or set
  "Eigen3_DIR" to a directory containing one of the above files.  If "Eigen3"
  provides a separate development package or SDK, be sure it has been
  installed.
Run Code Online (Sandbox Code Playgroud)

一般来说,当安装了 XXX 包(例如 Eigen3)时,该包应该配置该XXXConfig.cmake文件。这样外部项目就可以通过Config模式调用找到并使用find_package()XXX

由于您的 Eigen3 软件包未安装,因此Eigen3Config.cmake未配置该文件。因此,模块模式搜索应该适合您,因为FindEigen3.cmake您的 Eigen3 目录中仅存在该文件。对于模块模式,文件的路径FindEigen3.cmake必须添加到 中CMAKE_MODULE_PATH,如错误所示。在调用之前添加此行find_package(Eigen3 ...)可以使 CMake模块模式成功:

list(APPEND CMAKE_MODULE_PATH "C:/eigen-3.3.7/cmake")
Run Code Online (Sandbox Code Playgroud)