Unfortunately, i have some problems adding the headers only Eigen 3.3.7 Library to my Makefile with Cmake on my Ubuntu 18.04.4 LTS system.
I can compile my code using the library by just copying the library folder in the include directory and using
include_directories(./include/eigen3)
in the CMakeLists.txt file. However, i would much prefer not having the library path hard-coded but being able set it dynamically in the CMakeLists.txt file to make sharing the project with other people easier. Unfortunately, none of the instructions i found worked for me.
I prepared the following minimum code example:
main.cpp:
#include <eigen3/Eigen/Dense>
#include <iostream>
int main()
{
Eigen::Vector3d test_vec(1.0f, 2.0f, 3.0f);
std::cout << test_vec << std::endl;
return 0;
}
CMakeLists.txt:
cmake_minimum_required(VERSION 3.0)
project(Eigen-Cmake-Test VERSION 1.0) # set the project name
find_package (Eigen3 3.3 REQUIRED NO_MODULE)
include_directories(${EIGEN_INCLUDE_DIR})
# add the executable
add_executable("${PROJECT_NAME}" ./main.cpp)
target_link_libraries("${PROJECT_NAME}" Eigen3::Eigen)
I downloaded the headers only Eigen 3.3.7 Library and renamed the folder to eigen3. The folder was then moved to:
/usr/local/share/eigen3
when i run cmake CMakeLists.txt
i get the following error:
CMake Error at CMakeLists.txt:5 (find_package):
Could not find a package configuration file provided by "Eigen3" (requested
version 3.3) 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.
-- Configuring incomplete, errors occurred!
As i checked the Eigen library folder i realized that /usr/local/share/eigen3/cmake
only contained a file named Eigen3Config.cmake.in instead of Eigen3Config.cmake which was required. Why is this the case?
I tried renaming the file to Eigen3Config.cmake. Here the error was the following:
CMake Error at CMakeLists.txt:5 (find_package):
Could not find a configuration file for package "Eigen3" that is compatible
with requested version "3.3".
The following configuration files were considered but not accepted:
/usr/local/share/eigen3/cmake/Eigen3Config.cmake, version: unknown
-- Configuring incomplete, errors occurred!
Furthermore, i also tried the solutions explained stackoverflow: CMake find_package not working for Eigen? without success.
How can i make this work properly? Also i think i do not quite understand the underlying system yet. Any explanation would be appreciated.