How to I include Eigen Library in Clion
Answered
Eigen is an open source matrix manipulation library used in C++. I have downloaded the library,extracted and put it in the project. When I try this:
#include "Eigen/Dense"
This is not recognized and build fails.
Please sign in to leave a comment.
Hi!
For now CLion supports only CMake-based projects, so the library must be added to the project via CMake. This will enable both the successful build and the code-insight inside CLion. Please consult the Eigen manual about how use it via CMake: https://eigen.tuxfamily.org/dox/TopicCMakeGuide.html.
Hi!
I am facing problems when the find_package(Eigen) row is in a cmake file that is included to the main cmake file. The code-insight does not work in that case. If I move everything to the main file then it works, but I prefer to separate it into several files and open them using "include" in the main cmake file.
Best Pjeter
Hi Berisap!
>the find_package(Eigen) row is in a cmake file that is included to the main cmake file
Please specify how exactly you include this CMakeLists.txt into the top-level CMakeLists.txt.
Hi Anna!
Thank you for the quick response! So I have a C++ project that is built using cmake. In my project folder iIhave a "CMakeLists.txt" file where there is the codeline:
include("cmake/GetEigen.cmake")now in the subfolder "cmake" I have the file "GetEigen.cmake". In the "GetEigen.cmake" file I have the codeline:
With this configuration it seems that CLion is not able to recognize that I want to use the Eigen package in the project since the C++-Code looks like this:

Now when I remove the
include("cmake/GetEigen.cmake")and just copy-paste all the code from the "GetEigen.cmake" file in that position and reload everything the code insight seems to work as expected without errors:

Still I would prefer to have the Eigen related cmake codelines in the separate cmake file and still have CLion recognize it properly.
Thank you and best regards,
Pjeter
Berisap
I didn't manage to reproduce the issue in a simple project:
Please create a simple project with which the issue can be stably reproduced and send it to clion-support at jetbrains.com.
Hi Anna,
I tried to reproduce it, but the issue does not seem to appear anymore. Not even in the project I had the problem first. Sorry for bothering.
Best, Pjeter