Search code examples
c++cmakeeigenclion

How to link libs in CLion?


I'm using CLion as my IDE for C++ development and I'm trying to get Eigen included.

How do I do this? I've downloaded and unzipped Eigen and placed it in C:/ (Which I've read online is the path where CMake looks for libs when you use find_library())

In the CMakeLists.txt I've added

find_library(Eigen3 3.4 REQUIRED NO_MODULE)
add_executable(Lecture03 main.cpp)
target_link_libraries (Lecture03 Eigen3::Eigen)

But then it can't find Eigen, I get the following error when reloading my CMakeLists:

CMake Error at CMakeLists.txt:6 (find_library):
Could not find Eigen3 using the following names: 3.4

My question is, what did I do wrong? Did I place the Eigen folder in the wrong directory? Can I change where CMake looks for libs in CLion?


Solution

  • The solution ended up being to use

    include_directories(C:/CPP_Libs/Eigen3)
    

    in my CMakeLists.txt, and

    #include <Eigen/Dense>
    

    in whichever file needs it