CMake find_package not working for Eigen?
Asked Answered
G

2

7

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)

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?

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 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.

Giacinta answered 31/12, 2018 at 22:16 Comment(0)
F
8

You don't mention which version of Eigen3 is being used in each case.

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.

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} )

So just remove target_link_libraries(KFilter Eigen3::Eigen) and it should be fine.

Figment answered 1/1, 2019 at 3:18 Comment(2)
Yes it is the 3.3 beta version, thanks for clarifying! I’ll try this when I get a chance.Giacinta
well, and how to alias old version to new one?Alfaro
M
1

What worked for me using Ubuntu 16.04 was to remove the target_link_libraries(KFilter Eigen3::Eigen) and change in my source file the following line #include <eigen3/Eigen/Dense>

Malaya answered 8/5, 2019 at 9:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.