2

I encounter an issue when trying to build a little bit of code. (I'm on Linux)

To make it simple:

Here is what I've got in my Position.h file (at the really beginning, I think the next isn't necessary to solve that issue):

#include <Eigen/Dense>

And Here is my CMakeLists.txt:

project(p)
include_directories("./Eigen")
add_executable(
    p
    Eigen/Dense
    Position.h # which requires Eigen/Dense
    Position.cpp
    #other files
    )

In the project directory there is two directories: build and Eigen

To create the Makefile, I go in the build directory, then, type cmake ... A Makefile is created, but when I try to make I got the error:

/path/to/Position.h:30:23: fatal error: Eigen/Dense: no such file or directory.

Position.h is from a code picked up from GitHub (I can give you the link if wanted).

Please, can you give me a direction to search or maybe if you see what is wrong, what is my mistake

Thanks!

1 Answer 1

4

You can't give a header dependency as source files in add_executable(). And if Position.h does search Eigen/Dense you probably just need include_directories(.).

project(p)

include_directories(.)
add_executable(
    p
    Position.cpp
    Position.h
    #other files
)

But why don't you use find_module()?

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})

Reference

2
  • Thank you very much! the first one works perfectly =) I don't use finde_module because I didn't success to compile Eigen, and as it's not necessary (Eigen can work with only headers) I didn't took time. So thank you again for your help!
    – Tristan
    May 23, 2017 at 7:27
  • The second one is quite nice because cmake has a built in module which looks for Eigen and sets a variable with the include directory. It means that your project isn't dependant on Eigen residing in a specific location (relative or absolute). This will let you distribute your project to someone else or install it on another computer with another OS and as long as Eigen is installed in a reasonable location, cmake will find it.
    – Stewart
    May 23, 2017 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.