ubuntu 编译eigen3.4 和eigen3.3共存

eigen 安装

eigen 3.3.7


cmake \
  -DCMAKE_BUILD_TYPE=Release \
  -DEIGEN_BUILD_PKGCONFIG=ON \
  ..
sudo make install
# 安装位置:/usr/local/include/eigen3/

eigen 3.4.0

cmake \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_INSTALL_PREFIX=/usr/local/eigen3_4 \
  -DCMAKE_PREFIX_PATH=/usr/local/eigen3_4 \
  -DEIGEN_BUILD_PKGCONFIG=ON \
  ..

sudo make install
sudo cp /usr/local/eigen3_4/share/pkgconfig/eigen3.pc /usr/local/share/pkgconfig/eigen3.4.pc

配置pkg-config

cd /usr/local/share/pkgconfig/
sudo cp eigen3.pc eigen3.4.pc

## 以下为eigen3.3.7修改内容,保存
sudo geidit eigen3.pc
prefix=/usr/local
exec_prefix=${prefix}

Name: Eigen3
Description: A C++ template library for linear algebra: vectors, matrices, and related algorithms
Requires:
Version: 3.3.7
Libs:
Cflags: -I${prefix}/include/eigen3
## end

## 以下为eigen3.4.0修改内容,保存
sudo geidit eigen3.4.pc
prefix=/usr/local
exec_prefix=${prefix}

Name: Eigen3.4
Description: A C++ template library for linear algebra: vectors, matrices, and related algorithms
Requires:
Version: 3.4.0
Libs:
Cflags: -I${prefix}/include/eigen3_4
## end

cmake 查找

查找eigen3.4.0

find_package(PkgConfig)
pkg_search_module(EIGEN3 REQUIRED eigen3.4)
if(EIGEN3_FOUND)
	LIST(APPEND OpenMVS_EXTRA_INCLUDES ${EIGEN3_INCLUDE_DIRS})
	INCLUDE_DIRECTORIES(${EIGEN3_INCLUDE_DIRS})
	LIST(APPEND OpenMVS_DEFINITIONS -D_USE_EIGEN)
	ADD_DEFINITIONS(${EIGEN3_DEFINITIONS})
	SET(_USE_EIGEN TRUE)
	MESSAGE(STATUS "Eigen ${EIGEN3_VERSION} found (include: ${EIGEN3_INCLUDE_DIRS})")
endif()

查找eigen3.3.7

find_package(PkgConfig)
pkg_search_module(EIGEN3 REQUIRED eigen3)
if(EIGEN3_FOUND)
	LIST(APPEND OpenMVS_EXTRA_INCLUDES ${EIGEN3_INCLUDE_DIRS})
	INCLUDE_DIRECTORIES(${EIGEN3_INCLUDE_DIRS})
	LIST(APPEND OpenMVS_DEFINITIONS -D_USE_EIGEN)
	ADD_DEFINITIONS(${EIGEN3_DEFINITIONS})
	SET(_USE_EIGEN TRUE)
	MESSAGE(STATUS "Eigen ${EIGEN3_VERSION} found (include: ${EIGEN3_INCLUDE_DIRS})")
endif()

添加pkg-config 搜索路径

# 查找系统路径
pkg-config --variable pc_path pkg-config
/usr/local/lib/x86_64-linux-gnu/pkgconfig:/usr/local/lib/pkgconfig:/usr/local/share/pkgconfig:/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/lib/pkgconfig:/usr/share/pkgconfig


# 添加查找路径
gedit ~/.bashrc
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/eigen3_4/share/pkgconfig/
source ~/.bashrc

终端查看

pkg-config --cflags --libs eigen3
pkg-config --modversion eigen3

pkg-config --cflags --libs eigen3.4
pkg-config --modversion eigen3.4

posted @ 2022-03-30 21:29  小小灰迪  阅读(817)  评论(0编辑  收藏  举报