问题
I have a problem with the Eigen library. I use Clion on Linux and my project can't find the Eigen library (I have it in a folder on my desktop).
I have CMake in two configurations:
First:
cmake_minimum_required(VERSION 3.15)
project(TestFEM)
set(CMAKE_CXX_STANDARD 17)
set(EIGEN_DIR "~/Desktop/eigen-3.3.7")
include_directories(${EIGEN_DIR})
add_executable(TestFEM main.cpp FEM/FEM.cpp FEM/FEM.h)
And second:
cmake_minimum_required(VERSION 3.15)
project(TestFEM)
set(CMAKE_CXX_STANDARD 17)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})
add_executable(TestFEM main.cpp FEM/FEM.cpp FEM/FEM.h)
All the time, I have an error like this:
fatal error: Eigen\Dense: No such file or directory
How can I fix it?
回答1:
First, try using the full path to the Eigen directory (without ~
).
set(EIGEN_DIR "/home/xxxx/Desktop/eigen-3.3.7")
include_directories(${EIGEN_DIR})
Also, check to be sure that path actually contains Eigen/Dense
, so the full file path would be:
/home/xxxx/Desktop/eigen-3.3.7/Eigen/Dense
A better approach would be to use CMake to verify that path exists before using it:
set(EIGEN_DIR "/home/xxxx/Desktop/eigen-3.3.7")
if(NOT EXISTS ${EIGEN_DIR})
message(FATAL_ERROR "Please check that the set Eigen directory is valid!")
endif()
include_directories(${EIGEN_DIR})
But you can be even more safe by verifying you are in the correct location within the Eigen repository by using find_path(). The Eigen repository has a dummy file signature_of_eigen3_matrix_library
that you can use to verify you indeed found Eigen's top-level directory. Just use the PATHS
clause to tell CMake where to look:
find_path(EIGEN_DIR NAMES signature_of_eigen3_matrix_library
PATHS
/home/xxxx/Desktop/eigen-3.3.7
PATH_SUFFIXES eigen3 eigen
)
include_directories(${EIGEN_DIR})
来源:https://stackoverflow.com/questions/59794643/problem-with-including-eigen-library-in-clion-cmake