0

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?

Beginner
  • 325
  • 5
  • 16
  • Check my answer [here](http://stackoverflow.com/questions/12249140/find-package-eigen3-for-cmake/12258855#12258855) to learn how to search for Eigen in CMake. (But @jet47 is right in regard to your project being C, not C++) – Johannes S. Nov 12 '14 at 09:49
  • Thanks for your advice :) I tried what you mentioned in the other post but it doesn't solve the problem. The include directories of Eigen are already there and as I mentioned `cmake .` is not returning any error. What is missing though is including C++ standard libraries like `/usr/include/c++/4.8/` for example, which do not get automatically included since the project is a C project, as @jet47 pointed. Should I try to add those manually, or how should I proceed to use Eigen in this C project? – Beginner Nov 12 '14 at 10:49

1 Answers1

1

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

vinograd47
  • 6,320
  • 28
  • 30
  • Oh, now I see! Thanks for your reply. The whole project is written in C not in C++, I wasn't careful when I explained my situation. So changing main.c to main.cpp is not the right way to do it I guess... Do you know whether Eigen can be used for a C project? If yes, how to solve the include issues? – Beginner Nov 12 '14 at 09:02
  • 1
    As far as I know, Eigen is C++ library and can't be used in C project. But you can move all code that use Eigen to separate file and compile the file as C++, and leave the rest part of the project as C. – vinograd47 Nov 12 '14 at 16:47
  • Exactly, I think that's what I should do if I decide to stick to Eigen Many Thanks :) – Beginner Nov 12 '14 at 16:51