查看系统中是否已经安装
pkg-config --modversion eigen3
如果没有安装,按照如下步骤安装:
1:下载eigen源码包并解压
mkdir Download
cd ~/Download/
wget -O eigen.zip https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.zip
unzip eigen.zip
2:编译安装
cd ~/Download/eigen-3.3.7
mkdir build && cd build
cmake ..
sudo make install
3:测试代码
myeigen.cpp
#include <iostream>
#include <Eigen/Dense>
using Eigen::MatrixXd;
int main()
{
MatrixXd m(2,2);
m(0,0) = 3;
m(1,0) = 2.5;
m(0,1) = -1;
m(1,1) = m(1,0) + m(0,1);
std::cout << m << std::endl;
return 0;
}
CMakeLists.txt
cmake_minimum_required (VERSION 3.0)
project (myproject)
find_package (Eigen3 3.3.7 REQUIRED NO_MODULE)
add_executable (myEigen myeigen.cpp)
target_link_libraries (myEigen Eigen3::Eigen)
4:编译运行
mkdir build && cd build
cmake ..
make
./myEigen