Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake find_package not working for Eigen?

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.

like image 634
A Tyshka Avatar asked Dec 31 '18 22:12

A Tyshka


2 Answers

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.

like image 140
fdk1342 Avatar answered Oct 01 '22 20:10

fdk1342


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>

like image 26
Byron Quezada Avatar answered Oct 01 '22 21:10

Byron Quezada