Search code examples
c++makefilecmakeeigen

Issue between Eigen, make and cmake (probably a cmake mistake)


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!


Solution

  • 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