1 下载

git clone https://gitlab.com/libeigen/eigen.git

2 编译安装

cd eigen
mkdir build && cd build
cmake ..
make install

该方法默认安装在:
/usr/local/include/eigen3 /usr/local/share/eigen3

3 测试

将下面代码命名为testEigen.cpp:

#include <iostream>
#include <eigen3/Eigen/Dense>
using namespace std;
using namespace Eigen;

int main()
{
        Matrix2d a;
        a << 1, 2,
                3, 4;
        MatrixXd b(2, 2);
        b << 2, 3,
                1, 4;
        cout << "a + b =\n" << a + b << endl;
        cout << "a - b =\n" << a - b << endl;
        cout << "Doing a += b;" << endl;
        a += b;
        cout << "Now a =\n" << a << endl;
        cout << "a^T=  " << a.transpose() << endl;
        cout << "a*b= " << a*b << endl;
        Vector3d v(1, 2, 3);
        Vector3d w(1, 0, 0);
        cout << "-v + w - v =\n" << -v + w - v << endl;
        cout << v << endl;
        cout << v.transpose() << endl;
        system("pause");
return 0;
}

编译测试:

g++ testEigen.cpp -o a.out && ./a.out
Logo

更多推荐