Ubuntu 14.04/16.04/18.04安装最新版Eigen3.3.5

安装依赖

sudo apt-get install libopenblas-dev

sudo apt-get install --no-install-recommends libboost1.58-all-dev

sudo apt-get install libx11-dev

sudo apt-get install libgl1-mesa-dev 

sudo apt-get install libglu1-mesa-dev 

sudo apt-get install freeglut3-dev

sudo apt-get install doxygen

sudo apt-get install cmake

sudo wget https://nchc.dl.sourceforge.net/project/glew/glew/2.1.0/glew-2.1.0.tgz --no-check-certificate

sudo tar -xzvf glew-2.1.0.tgz

cd glew-2.1.0/

sudo make 

sudo make install

sudo ldconfig -v

安装Eigen3.3.5


sudo wget https://github.com/eigenteam/eigen-git-mirror/archive/3.3.5.tar.gz

sudo tar -xzvf 3.3.5.tar.gz 

sudo mv eigen-git-mirror-3.3.5/ eigen-3.3.5/

cd eigen-3.3.5/

sudo mkdir build

sudo cmake ..

sudo make

sudo make install 

sudo ldconfig -v

测试

#CMakeLists.txt

cmake_minimum_required( VERSION 2.8 )
project(useEigen)

set( CMAKE_BUILD_TYPE "Release" )
set( CMAKE_CXX_FLAGS "-O3" )
set( CMAKE_CXX_FLAGS "-std=c++11")

# 添加Eigen头文件
include_directories( "/usr/local/include/eigen3" )


add_executable(useEigen  main.cpp)
find_package(Eigen3 REQUIRED)
target_link_libraries(${PROJECT_NAME}  ${EIGEN3_LIBS})
//main.cpp

#include 
#include 
#include 

#include 
#include 
#include 
#include 

using namespace std;
int main()
{
    //1.rotation vector to  rotation matrix
    Eigen::AngleAxisd rotationVector(M_PI/4,Eigen::Vector3d(0,0,1));
    Eigen::Matrix3d rotationMatrix=Eigen::Matrix3d::Identity();
    rotationMatrix=rotationVector.toRotationMatrix();
    cout<<"rotationMatrix \n"<//2.rotation vector to quaterniond
    Eigen::Quaterniond q=Eigen::Quaterniond( rotationVector );
    cout<<"rotation quaternion \n"<//3.rotaion vector to eulerAngles
    Eigen::Vector3d eulerAngle=rotationVector.matrix().eulerAngles(0,1,2);
    cout<<"eulerAngle roll pitch yaw\n"<<180*eulerAngle/M_PI<return 0;
}

CMakeLists.txtmain.cpp放到同一个目录,执行:

sudo cmake  .
sudo make
./useEigen

如果能输出:

rotationMatrix 
 0.707107 -0.707107         0
 0.707107  0.707107         0
        0         0         1
rotation quaternion 
       0
       0
0.382683
 0.92388
eulerAngle roll pitch yaw
-0
 0
45

证明Eigen 3.3.5安装成功并且可以被cmake查找引用到.

你可能感兴趣的:(C++,自动驾驶,slam)