在Clion CMake中包含本征库的问题 [英] Problem with including Eigen library in Clion CMake

查看:45
本文介绍了在Clion CMake中包含本征库的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Eigen库有问题.我在Linux上使用Clion,但我的项目找不到Eigen库(我在桌面上的文件夹中).

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).

我有两种配置的CMake:

I have CMake in two configurations:

第一:

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)

第二:

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

我该如何解决?

推荐答案

首先,尝试使用Eigen目录的 full 路径(不带).

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})

此外,请检查以确保路径实际上包含 Eigen/Dense ,因此完整的文件路径应为:

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

更好的方法是使用CMake在使用之前先验证该路径是否存在:

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})

但是通过使用中,您甚至可以更加安全.16/command/find_path.html"rel =" nofollow noreferrer> find_path() .Eigen存储库中有一个虚拟文件 signature_of_eigen3_matrix_library ,您可以使用该文件来验证您是否确实找到了Eigen的顶级目录.只需使用 PATHS 子句告诉CMake看哪里:

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})

这篇关于在Clion CMake中包含本征库的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆