我正在尝试安装本征,但我似乎无法让它发挥作用。
我做到了:
sudo apt-get install libeigen3-dev
一切似乎都很好,之后
dpkg -p libeigen3-dev
我得到:
Package: libeigen3-dev
Priority: extra
Section: libdevel
Installed-Size: 3718
Maintainer: Ubuntu Developers <[email protected]>
Architecture: all
Source: eigen3
Version: 3.2.0-4
Depends: pkg-config
Suggests: libeigen3-doc
Size: 698062
Description: lightweight C++ template library for linear algebra
Eigen 3 is a lightweight C++ template library for vector and matrix math,
a.k.a. linear algebra.
.
Unlike most other linear algebra libraries, Eigen 3 focuses on the simple
mathematical needs of applications: games and other OpenGL apps, spreadsheets
and other office apps, etc. Eigen 3 is dedicated to providing optimal speed
with GCC. A lot of improvements since 2-nd version of Eigen.
Original-Maintainer: Debian Science Maintainers <[email protected]>
Homepage: http://eigen.tuxfamily.org
在我看来一切都很好。然而,当我尝试编译基本代码(在教程中给出)时:
第一个特征值.cpp
#include <iostream>
#include <Eigen/Dense>
using namespace Eigen;
int main()
{
Matrix2d a;
a << 1, 2,
3, 4;
MatrixXd b(2,2);
b << 2, 3,
1, 4;
std::cout << "a + b =\n" << a + b << std::endl;
std::cout << "a - b =\n" << a - b << std::endl;
std::cout << "Doing a += b;" << std::endl;
a += b;
std::cout << "Now a =\n" << a << std::endl;
Vector3d v(1,2,3);
Vector3d w(1,0,0);
std::cout << "-v + w - v =\n" << -v + w - v << std::endl;
}
我在 shell 中像这样运行它:
g++ -std=c++11 first_eigen.cpp -o my_exec
我收到以下错误:
first_eigen.cpp:2:23: fatal error: Eigen/Dense: No such file or directory
#include <Eigen/Dense>
^
compilation terminated.
看起来好像eigen
没有安装。我遗漏了什么?
答案1
头文件eigen3
放在子目录中/usr/include/eigen3
,例如
/usr/include/eigen3/Eigen/Array
/usr/include/eigen3/Eigen/Cholesky
/usr/include/eigen3/Eigen/CholmodSupport
/usr/include/eigen3/Eigen/Core
/usr/include/eigen3/Eigen/Dense
/usr/include/eigen3/Eigen/Eigen
因此您需要在编译器命令行上指定附加包含路径,例如
g++ -std=c++11 -I/usr/include/eigen3 first_eigen.cpp -o my_exec
或者(可能更方便),您可以使用pkg-config
数据库来自动执行包含,即
g++ -std=c++11 `pkg-config --cflags eigen3` first_eigen.cpp -o my_exec
答案2
将包含更改为
#include <eigen3/Eigen/Dense>
答案3
请检查 /usr/include 中是否有一个名为“Eigen”的文件夹。
我不知道 eigen 和安装程序。但 dev 包含的内容通常以版本命名。
如果您的 /usr/include 目录中有一个“Eigen3”文件夹,则应将代码更改为:
#include <Eigen3/Dense>