includecmakeeigen

How to include in CMake the files on which Eigen depends?


I am working on a C project which I downloaded from the Internet. I am trying to add some functions in which Eigen is to be used for linear algebra.

To that end, I added the following lines to the CMakeLists.txt :

PKG_CHECK_MODULES(EIGEN3 REQUIRED eigen3)
INCLUDE_DIRECTORIES(${EIGEN3_INCLUDE_DIRS})
LINK_DIRECTORIES(${EIGEN3_LIBRARY_DIRS})
ADD_EXECUTABLE(main main.c)
TARGET_LINK_LIBRARIES(main ${EIGEN3_LIBRARIES})

and I get no errors when running cmake . and then make

The issue is when I try to include <Eigen/Dense> in one of the c functions, I get the following error when I try to make:

/usr/include/eigen3/Eigen/Core:28:19: fatal error: complex: No such file or directory  #include <complex>

Eigen/Dense includes Eigen/Core and Eigen/Core includes <complex> I think it's just not looking in the correct directory to find complex... How to make it look there?


Solution

  • Eigen is a C++ library, while your application source is a C file (main.c). Since it has a .c extension, CMake treats it as C source and uses the C compiler, which doesn't know about the C++ standard library (<complex>). Rename main.c to main.cpp.