Error with Clion/Cmake and Eigen

2019-07-27 02:57发布

I am trying to get Eigen up and running but I am running into a roadblock. I opened Clion and in the CMakeLists.txt tab I entered the following code. Please note I have installed Eigen with home-brew.

project(untitled)

cmake_minimum_required(VERSION 3.7)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

find_package(Eigen3 REQUIRED)

include_directories(EIGEN3_INCLUDE_DIR)

set(SRCS main.cpp)

add_executable(untitled ${SRCS})

I am getting the following error.

/Applications/CLion.app/Contents/bin/cmake/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /Users/johnmcconnell/CLionProjects/untitled
CMake Error at CMakeLists.txt:9 (find_package):
  Found package configuration file:

    /usr/local/share/eigen3/cmake/Eigen3Config.cmake

  but it set Eigen3_FOUND to FALSE so package "Eigen3" is considered to be
  NOT FOUND.

I've never done this before and I am really at a loss, any ideas on what to do?

UPDATE: Change in code clears the error but yields a new one.

fatal error: 'Eigen/Dense' file not found

project(untitled)

cmake_minimum_required(VERSION 3.7)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

include_directories(EIGEN_INCLUDE_DIR)

set(SRCS main.cpp)

add_executable(untitled ${SRCS})

标签: cmake eigen
3条回答
再贱就再见
2楼-- · 2019-07-27 03:35

If you look at the source code of the CMake module: https://github.com/RLovelett/eigen/blob/master/cmake/FindEigen3.cmake

You can see that it accepts "hints" in either EIGEN3_ROOT or EIGEN3_ROOT_DIR. Set one of those to the base of your Eigen installation and try again:

EIGEN3_ROOT=blah/blah cmake ...
查看更多
时光不老,我们不散
3楼-- · 2019-07-27 03:36
  • Include the following in CMakeLists.txt

    set(EIGEN_DIR "C:\\Eigendir\\Eigen")
    include_directories(${EIGEN_DIR})
    add_executable(project_name main.cpp)
    target_link_libraries(project_name ${EIGEN_DIR})
    
  • The directory in which you placed Eigen's source code must be in the include path

  • EIGEN_DIR is set to the path where the Eigen folder is in your system
  • This worked for me and do not forget the #include <Eigen> in the files where ever you are using Eigen... Hope this answer helps you :D
查看更多
聊天终结者
4楼-- · 2019-07-27 03:46

In addition to the problem solved by @John Zwinck's answer, you have an error in your include_directories statement.

It should be

include_directories(${EIGEN3_INCLUDE_DIR})

instead of

include_directories(EIGEN_INCLUDE_DIR)
查看更多
登录 后发表回答