特征装置似乎有效,但我仍然无法做出特殊的工作

Modified on: Thu, 14 Jun 2018 10:32:23 +0800

我正在尝试安装eigen,但我似乎无法使用它。

我做了:

sudo apt-get install libeigen3-dev

之后,一切似乎都很好

dpkg -p libeigen3-dev

我明白了:

Package: libeigen3-dev
Priority: extra
Section: libdevel
Installed-Size: 3718
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
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 <debian-science-maintainers@lists.alioth.debian.org>
Homepage: http://eigen.tuxfamily.org

一切看起来都很好。但是,当我尝试编译基本代码时(在教程中给出):

first_eigen.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。我错过了什么?

作者:Akavall

最佳答案

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

因此您需要在编译器命令行中指定其他包含路径,例如

/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

或者(可能更便携),您可以使用pkg-config数据库自动包含,即

g++ -std=c++11 -I/usr/include/eigen3 first_eigen.cpp -o my_exec

相关问答

添加新评论