我有点绝望:对于我的学习,我需要与Eigen和CMake合作.我能够使用Eigen,如果我将整个库复制到我的编译器默认查找的目录中,但是一旦我尝试通过它找到它
find_package(Eigen3 REQUIRED)
我得到以下错误:
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!
现在我搜索了解决方案,但我尝试过的所有(也是stackoverflow上的那些:
查找包Eigen3 for CMake
或
CMake找不到Eigen3)都不起作用.我的Eigen版本(根据Macros 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) include_directories(${EIGEN3_INCLUDE_DIR}) message("Found Eigen3 in: ${EIGEN3_INCLUDE_DIR}") add_executable(main test.cpp)
有谁知道出了什么问题?
亲切的问候,朱利安
将我的评论转化为答案
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 )
所以它默认CMAKE_INSTALL_PREFIX
在Unix/Linux主机上查找/usr/local
.
以下对我有用:
转到Eigen
源目录并运行CMake和安装步骤
> mkdir build > cd build > cmake .. > make install
然后将 - 如您所做的那样 - 复制FindEigen3.cmake
到项目源目录中.
现在你的代码确实找到了Eigen
(只是改为list(APPEND ...)
)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}") find_package(Eigen3 REQUIRED)
参考
Eigen&CMake
CMake:如果你需要指定CMAKE_MODULE_PATH,find_package()的用途是什么?
Cmake找不到Boost