为什么Eigen无法解析内置符号? (全部,最后,seq等...)

问题描述 投票:0回答:1

我从Eigen documentation网站上获得了有关切片和inexing的这段代码:

#include <iostream>
#include <Eigen>
#include <vector>
using namespace std;
using namespace Eigen;

int main() {
    std::vector<int> ind{4,2,5,5,3};
    MatrixXi A = MatrixXi::Random(4,6);
    cout << "Initial matrix A:\n" << A << "\n\n";
    cout << "A(all,ind):\n" << A(all,ind) << "\n\n";

    return 0;
}

[当我尝试编译时,出现多个错误,例如:

  • [all不是Eigen的成员
  • all未在此范围内声明
  • last未在此范围内声明
  • [seq不是Eigen的成员
  • 无法解析功能seq
  • [MatrixXi::Random无效参数

我该如何解决这些错误?


[好像我使用的Eigen版本错误(它的工作是here),但是,根据this的答案,我有:EIGEN_WORLD_VERSION 3EIGEN_MAJOR_VERSION 3EIGEN_MINOR_VERSION 7,我相信这是最新的。

就安装而言,我将Eigen文件夹复制到项目位置,并为g ++编译器提供了该文件夹的路径(-I标志)。图书馆本身似乎运作良好;例如,此代码(来自提供的示例)可以正常工作:

#include <iostream>
#include <Eigen>
//#include <Eigen/Dense> // I had to change this though
                         // I get an error: 'no such file or directory'

using namespace Eigen;
using namespace std;

int main()
{
  Matrix3d m = Matrix3d::Random();
  m = (m + Matrix3d::Constant(1.2)) * 50;
  cout << "m =" << endl << m << endl;
  Vector3d v(1,2,3);

  cout << "m * v =" << endl << m * v << endl;
}
c++ eigen3
1个回答
0
投票

您的问题可能是g ++的-I选项

我怀疑您有类似的东西:

g++  ....  -I<path_to_project>/Eigen

...,而应仅是

g++  ....  -I<path_to_project>

...即最终Eigen目录不应位于包含路径上。

进行此更改,然后还更改源代码,以便所有包含的内容都类似于:

#include <Eigen/Dense>
#include <Eigen/Cholesky>

另外,您引用的是变量all,但您的程序尚未定义它。

还要确保您至少启用了c ++ 11编译器选项。

© www.soinside.com 2019 - 2024. All rights reserved.