如何安装eigen3将eigen3加入到cmake

eigen从官网上下载了之后解压。
1.基础配置
在你新建的项目中include里面加上就行,目录是解压后的文件夹。
然后在代码中加上&#include &Eigen/Dense& &这一行
注意看红色部分entry最后一行,添加1中一样的目录即可。
白费了好长时间竟然 没有注意到这里=。=原来选择上就行的= =
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:13601次
排名:千里之外
原创:28篇
转载:29篇
(2)(2)(2)(1)(2)(4)(2)(1)(4)(6)(3)(2)(4)(8)(2)(1)(3)(3)(2)(1)(2)CMAKE(3)
Ubuntu(44)
Eigen(20)
the reason is missing EIGEN3_INCLUDE_DIR
then we need to define it in cmakelist.txt file
add a line like this in this file:
Set(EIGEN3_INCLUDE_DIR &/usr/local/include/eigen-eigen-b30b87236a1b&)
there are somthing about cmake referenced from /questions//find-package-eigen3-for-cmake
Since Eigen3 is completely header only, all you ever need is the path to the include directory. And this one, you are already defining manually anyway. So there is no real need for a
FindEigen3.cmake or FIND_PACKAGE call.
Simply use
INCLUDE_DIRECTORIES ( &$ENV{EIGEN3_INCLUDE_DIR}& )
SET( EIGEN3_INCLUDE_DIR &$ENV{EIGEN3_INCLUDE_DIR}& )
IF( NOT EIGEN3_INCLUDE_DIR )
MESSAGE( FATAL_ERROR &Please point the environment variable EIGEN3_INCLUDE_DIR to the include directory of your Eigen3 installation.&)
INCLUDE_DIRECTORIES ( &${EIGEN3_INCLUDE_DIR}& )
A few notes:
If you want to access the content of a CMake variable, make sure to use
${...}$ENV{....} accesses environment variables.The second example will stop with an error if the environment variable is not set (and, thus, EIGEN3_INCLUDE_DIR cmake variable is empty)Be careful to use quotation marks around (evaluated) variables if they could contain whitespace. Otherwise, CMake will interpret it as a list.If you want to use custom find modules, make sure to either place them in you CMake installation or, as @Fraser pointed out above, make sure to point
CMAKE_MODULE_PATH to the directory where it is. Not sure, but it could be that CMake checks the current directory as well automatically (where your
CMakeLists.txt resides. Anyhow, setting EIGEN3_INCLUDE_DIR is totally unrelated to the location of
FindEigen3.cmakeHowever, it could be that your FindEigen3 script evaluates this variable to determine the location of your Eigen3 installation.Alternatively, self-built CMake-based projects often provide a &PackageName&Config.cmake. If you point a variable called
&PackageName&_DIR to the directory containing this file, you can use
FIND_PACKAGE( &PackageName& ...) as normal. See
for details.
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:170481次
积分:6567
积分:6567
排名:第2568名
原创:490篇
转载:79篇
评论:73条
(3)(9)(11)(25)(29)(28)(5)(69)(50)(29)(39)(82)(10)(2)(5)(2)(2)(3)(6)(22)(7)(7)(34)(21)(3)(3)(5)(2)(4)(8)(14)(6)(16)(4)(3)(1)重新认识Eigen C++库 - 简书
下载简书移动应用
写了96936字,被60人关注,获得了82个喜欢
重新认识Eigen C++库
是我之前为写一个通用的数学工具库时了解并第一次使用的,但当时只是随意的一用,甚至没有仔细研究它的编译方法,这也让我对它的使用产生了一些误解。最大的一个误解便是以为它是需要使用cmake进行编译才可以使用的,原因是之前所做工程和Eigen本身都是cmake管理的,于是便留下了这个想当然的概念。
一个结果就是,在前段时间为一个特定工程编写一个数据分析库时,为求和他人的Qt程序(使用qmake)兼容,我错误的认为把“cmake管理”的Eigen库加入进来会很麻烦,便把之前用Eigen矩阵已然写好的拟合计算类(属于我之前所做的工具库)进行改造,换用了标准C++下的vector(矩阵就用vector&vector&嵌套实现)。虽然实现了,但效率方面、性能方面都显然不理想,而且这明显是一种错误的改造方向(由高效、便捷到低效、繁杂)。
于是在这个假期的空档,我决定研究一下,把Eigen编译成一个第三方库来使用的。但两年之后重新看Eigen的帮助,才惊异的发现它是不依赖cmake的,仅需要加入头文件,换句话说其源码应该是封装在头文件中的……我一边为自己之前白费的力气惋惜,一方面开始构想回去工作之后,第一件事就是把Eigen换回来。这样,当年仅凭兴趣写下的整个工具库都可以在真实的工程中得到应用和验证,也可以重新来学习一下Eigen的使用(话说当年看的也太粗糙了)。
另一个发现就是Eigen中矩阵和向量类的灵活性大大的超出了我曾经的理解,不仅可以适配任意的维度和数据类型,而且可以对行和列分别进行控制,即行和列都可以自由的指定为固定长度或动态长度。这样,在仅有一个维度确定的情况下,也可以通过固定其长度来提高计算效率,如下所示:
Matrix&double, 6, Dynamic&
// Dynamic number of columns (heap allocation)
Matrix&double, Dynamic, 2&
// Dynamic number of rows (heap allocation)
此外,我还发现,只要加入Eigen::initParallel(),Eigen就可以利用OpenMP的API来进行多核计算。
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
选择支付方式:eigen - Find package Eigen3 for CMake - Stack Overflow
to customize your list.
Join the Stack Overflow Community
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
J it only takes a minute:
CMake cannot find my Eigen3 package. I set an environment variable called
EIGEN3_INCLUDE_DIR
pointing to the path where FindEigen3.cmake is.
Then in the CMakelists.txt I wrote:
find_package( Eigen3 REQUIRED )
include_directories( EIGEN3_INCLUDE_DIR )
I get next message of error:
CMake Error at C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:91 (MESSAGE):
Could NOT find Eigen3 (missing: EIGEN3_INCLUDE_DIR EIGEN3_VERSION_OK)
(Required is at least version "2.91.0")
Call Stack (most recent call first):
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:252 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files (x86)/CMake 2.8/share/cmake-2.8/Modules/FindEigen3.cmake:76 (find_package_handle_standard_args)
test/test_quaternion/CMakeLists.txt:25 (find_package)
Any idea on what I am missing or doing wrong?
15.1k1484139
Since Eigen3 is completely header only, all you ever need is the path to the include directory. And this one, you are already defining manually anyway. So there is no real need for a FindEigen3.cmake or FIND_PACKAGE call.
Simply use
INCLUDE_DIRECTORIES ( "$ENV{EIGEN3_INCLUDE_DIR}" )
SET( EIGEN3_INCLUDE_DIR "$ENV{EIGEN3_INCLUDE_DIR}" )
IF( NOT EIGEN3_INCLUDE_DIR )
MESSAGE( FATAL_ERROR "Please point the environment variable EIGEN3_INCLUDE_DIR to the include directory of your Eigen3 installation.")
INCLUDE_DIRECTORIES ( "${EIGEN3_INCLUDE_DIR}" )
A few notes:
If you want to access the content of a CMake variable, make sure to use ${...}
$ENV{....} accesses environment variables.
The second example will stop with an error if the environment variable is not set (and, thus, EIGEN3_INCLUDE_DIR cmake variable is empty)
Be careful to use quotation marks around (evaluated) variables if they could contain whitespace. Otherwise, CMake will interpret it as a list.
If you want to use custom find modules, make sure to either place them in you CMake installation or, as @Fraser pointed out above, make sure to point CMAKE_MODULE_PATH to the directory where it is. Not sure, but it could be that CMake checks the current directory as well automatically (where your CMakeLists.txt resides. Anyhow, setting EIGEN3_INCLUDE_DIR is totally unrelated to the location of FindEigen3.cmake
However, it could be that your FindEigen3 script evaluates this variable to determine the location of your Eigen3 installation.
Alternatively, self-built CMake-based projects often provide a &PackageName&Config.cmake. If you point a variable called &PackageName&_DIR to the directory containing this file, you can use FIND_PACKAGE( &PackageName& ...) as normal. See
for details.
First, make sure Eigen is properly installed. Refer to the INSTALL file that comes with the tarball.
Second, copy the cmake/FindEigen3.cmake file from the tarball to the directory containing your CMakeLists.txt.
In your CMakeLists.txt add:
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR})
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIR})
Now you should be able to do e.g. #include &Eigen/Core&.
All of this comes (mostly) from this .
This approach has the advantage over e.g. include_directories("$ENV{EIGEN3_INCLUDE_DIR}") that it the uses CMake's standard mechanism for finding external dependencies, making it easier for someone else (or your future self) to pick up the project, possibly on another platform.
(However, it would be nice if Eigen itself installed an EigenConfig.cmake file, making it accessible through the find_package mechanism without any extra paths.)
I found another solution
(which referred to ) which uses the pkg-config file :
find_package(PkgConfig)
pkg_search_module(Eigen3 REQUIRED eigen3)
2,66371532
You could try setting the CMAKE_MODULE_PATH to the location of Eigen subdirectory named "cmake":
cmake . -DCMAKE_MODULE_PATH=&Eigen root dir&/cmake/
36k6101124
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabledLinux(29)
这才刚刚开头,可是就是不知道错误在哪里?百度了问题后,打开了很多很多相关的解答,从昨天上午遇到这个问题,历经昨天下午和晚上,还是错误,终于在今天上午圆满解决了问题,但是也为自己的低效率担忧。
错误截图如下:
CMake Error atCMakeLists.txt:23 (find_package):
By not providing&FindEigen3.cmake& in CMAKE_MODULE_PATH this project has
asked CMake tofind a package configuration file provided by &Eigen3&, but
CMake did not findone.
Could not find apackage configuration file provided by &Eigen3& with any
of the followingnames:
Eigen3Config.cmake
eigen3-config.cmake
Add theinstallation prefix of &Eigen3& to CMAKE_PREFIX_PATH or set
&Eigen3_DIR&to a directory containing one of the above files. If &Eigen3&
provides aseparate development package or SDK, be sure it has been
installed.
百度的原因都是说项目下的 CMakeLists.txt 配置的不正确,无论如何配置都不正确
不过还好还好,终于找到终极解决方法。
以root 账号进入 Fedora 系统, 普通用户执行的时候出错。
给出项目的大致框架:项目名: TestDemo& ,& eigen 在文件夹 TestDemo中,
运行语句: cmake .. -DEIGEN3_INCLUDE_DIR=eigen -DCMAKE_CXX_COMPILER=/usr/bin/clang++
出现开头的错误。
解决方法如下, 原地址: /questions//unable-to-find-eigen3-with-cmake
Go to the Eigen source directory and run the CMake and installation steps
& mkdir build
& cd build
& cmake ..
& make install
问题完美解决。执行结果如下:
[root@localhost build]# cmake .. -DEIGEN3_INCLUDE_DIR=eigen -DCMAKE_CXX_COMPILER=/usr/bin/clang++
-- Boost version: 1.58.0
-- Found the following Boost libraries:
--&& program_options
--&& serialization
-- Configuring done
-- Generating done
-- Build files have been written to: /root/software/LSTM-ER/build
错误原因分析:下载的Eigen 是源码(个人认为,待考证)
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:42800次
积分:1962
积分:1962
排名:第14943名
原创:150篇
转载:65篇
(15)(6)(4)(4)(1)(4)(8)(2)(13)(16)(8)(8)(9)(3)(5)(8)(8)(6)(15)(1)(33)(9)(17)(6)(3)(1)(3)}

我要回帖

更多关于 如何安装eigen3 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信