问题描述
我目前正在使用Eigen开发一个Kalman过滤库,并且已经成功地在我的开发Mac上运行它。现在,我正在尝试使用Travis CI进行设置,而CMake找不到软件包。首先,我 sudo apt install libeigen3-dev
,然后尝试使用以下配置运行cmake:
I'm currently developing a Kalman Filtering library using Eigen and I've successfully gotten it working on my development Mac. Now I'm trying to set it up with Travis CI and CMake is having trouble with finding the package. First I sudo apt install libeigen3-dev
and then attempt to run cmake with the following configuration:
cmake_minimum_required(VERSION 3.0)
project(KFilter VERSION 0.1.0)
find_package (Eigen3 REQUIRED NO_MODULE)
add_library(KFilter KFilter.cpp)
target_link_libraries(KFilter Eigen3::Eigen)
这在我的Mac上很好用,但在Travis中CI,它会出错,并显示以下内容:
This builds just fine on my Mac, but in Travis CI it errors out with the following:
CMake Error at CMakeLists.txt:5 (add_library):
Target "KFilter" links to target "Eigen3::Eigen" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?
当find_package似乎成功时,为什么在第5行出现此错误?我正在跟踪Eigen网站上的指南。
Why is would I be getting this error at line 5 when the find_package seems to be successful? I'm following this guide from the Eigen website.
Travis CI在Ubuntu 16.04上运行CMake 3.12和Eigen3 debian软件包,而我的Mac在CMake 3.13上运行Eigen通过自制软件安装。我真的对为什么CMake的行为有所不同感到困惑。
Travis CI is running Ubuntu 16.04 with CMake 3.12 and the Eigen3 debian package, while my Mac is running CMake 3.13 with Eigen installed through homebrew. I'm really confused as to why CMake is behaving differently.
推荐答案
您没有提到正在使用哪个版本的Eigen3
You don't mention which version of Eigen3 is being used in each case.
在Eigen3 3.2和3.3之间看起来从使用 FindEigen3.cmake
更改为 Eigen3Config.cmake
。这改变了如何将Eigen3包含到项目中,并在3.3中使用了 Eigen3 :: Eigen3
。
It looks like between Eigen3 3.2 and 3.3 it changed from using FindEigen3.cmake
to Eigen3Config.cmake
. This changed how to include Eigen3 into a project and in 3.3 it uses Eigen3::Eigen3
.
事实证明,在Ubuntu 16.04上,软件包为 libeigen3-dev(3.3〜beta1-2)
,而3.3 beta版未导出 Eigen3 :: Eigen3
相反,它包含:
But as it turns out on Ubuntu 16.04 the package is libeigen3-dev (3.3~beta1-2)
and 3.3 beta versions didn't export Eigen3::Eigen3
instead it contains:
add_definitions ( ${EIGEN3_DEFINITIONS} )
include_directories ( ${EIGEN3_INCLUDE_DIRS} )
所以只需删除 target_link_libraries(KFilter Eigen3 :: Eigen)
,应该没问题。
So just remove target_link_libraries(KFilter Eigen3::Eigen)
and it should be fine.
这篇关于CMake find_package对本征不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!