1. 背景
maplab是瑞士苏黎世理工推出的一套带vslam的vio前端和带dense reconstruction后端的工具,在本文写作时已经算比较老的一套代码了,因此此时再执行安装编译也许就会出现各种问题。我反正是没想到我会耗费大半天的时间才终于安装编译测试成功。在此记录整个过程,想要节省时间的朋友也可直接阅读第3部分。
2. 安装编译过程
2.1 相关链接
maplab github仓库 【1】
ubuntu平台安装maplab流程 【2】
maplab安装编译常见问题 【3】
带ippicv压缩包的opencv 3.2.0 【4】
2.2 计算机A安装编译过程
- 计算机A环境:无GPU,ubuntu 16.04,ROS kinetic,ceres、glog、eigen、protobuf 2.6.1已安装,gcc/g++5\6\7\8
按照2.1链接【3】的介绍,ceres、glog、eigen、protobuf这些包在maplab文件夹里都有提供,再加上网络不稳定的因素,下载maplab仓库需要很长时间,编译时还会产生问题。
按照2.1链接【2】介绍的过程进行安装编译,直到最后一步:
catkin build maplab
接下来是产生的问题和解决办法:
- 2.2.1
CMake Error at cmake/OpenCVCompilerOptions.cmake:21 (else):
A duplicate ELSE command was found inside an IF block.
Call Stack (most recent call first):
CMakeLists.txt:495 (include)
make[2]: *** [opencv3_src-prefix/src/opencv3_src-stamp/opencv3_src-configure] Error 1
make[1]: *** [CMakeFiles/opencv3_src.dir/all] Error 2
make: *** [all] Error 2
找到OpenCVCompilerOptions.cmake,发现该文件21行多了一个语法错误的else(),注释掉即可,再次编译:
- 2.2.2
CMake Error at cmake/OpenCVFindIPP.cmake:243 (include):
include could not find load file:
/home/(隐藏)/maplab_ws/build/opencv3_catkin/opencv3_src/3rdparty/ippicv/downloader.cmake
Call Stack (most recent call first):
cmake/OpenCVFindLibsPerf.cmake:37 (include)
CMakeLists.txt:558 (include)
CMake Warning at cmake/OpenCVFindLAPACK.cmake:29 (message):
LAPACK(Unknown): CBLAS/LAPACK headers are not found in ‘’
Call Stack (most recent call first):
cmake/OpenCVFindLAPACK.cmake:151 (ocv_lapack_check)
CMakeLists.txt:559 (include)
CMake Error at cmake/OpenCVUtils.cmake:1043 (file):
file DOWNLOAD HASH mismatch
for file: [/home/(隐藏)/maplab_ws/build/opencv3_catkin/opencv3_contrib_src/modules/xfeatures2d/cmake/.download/e8d0dcd54d1bcfdc29203d011a797179/vgg_generated_48.i]
expected hash: [e8d0dcd54d1bcfdc29203d011a797179]
actual hash: [d41d8cd98f00b204e9800998ecf8427e]
status: [7;“Couldn’t connect to server”]
Call Stack (most recent call first):
/home/(隐藏)/maplab_ws/build/opencv3_catkin/opencv3_contrib_src/modules/xfeatures2d/cmake/download_vgg.cmake:13 (ocv_download)
/home/(隐藏)/maplab_ws/build/opencv3_catkin/opencv3_contrib_src/modules/xfeatures2d/cmake/download_vgg.cmake:20 (vgg_download)
/home/(隐藏)/maplab_ws/build/opencv3_catkin/opencv3_contrib_src/modules/xfeatures2d/CMakeLists.txt:4 (include)
CMake Error at cmake/OpenCVUtils.cmake:1047 (message):
Failed to download vgg_generated_48.i. Status=7;“Couldn’t connect to
server”
Call Stack (most recent call first):
/home/(隐藏)/maplab_ws/build/opencv3_catkin/opencv3_contrib_src/modules/xfeatures2d/cmake/download_vgg.cmake:13 (ocv_download)
/home/(隐藏)/maplab_ws/build/opencv3_catkin/opencv3_contrib_src/modules/xfeatures2d/cmake/download_vgg.cmake:20 (vgg_download)
/home/(隐藏)/maplab_ws/build/opencv3_catkin/opencv3_contrib_src/modules/xfeatures2d/CMakeLists.txt:4 (include)
make[2]: *** [opencv3_src-prefix/src/opencv3_src-stamp/opencv3_src-configure] Error 1
make[1]: *** [CMakeFiles/opencv3_src.dir/all] Error 2
make: *** [all] Error 2
可见是opencv3_catkin/opencv3_contrib_src/modules/xfeatures2d/相关的下载出现了问题,那么按照2.1链接【3】中有提到的问题解决办法:
从 https://github.com/Itseez/opencv/archive/3.2.0.zip 下载opencv-3.2.0压缩包,并解压缩,将“opencv-3.2.0”文件夹内的内容复制到:
~/maplab_ws/build/opencv3_catkin/opencv3_src 之内
后文可知,这样做对我来说没起多大作用。
因为覆盖了build/opencv3_catkin/opencv3_src,因此别忘了再次修改2.2.1中提到的内容。再次编译:
- 2.2.3
Errors << opencv3_catkin:make /home/(隐藏)/maplab_ws/logs/opencv3_catkin/build.make.006.log
/usr/bin/ld: cannot find -lopencv_core
collect2: error: ld returned 1 exit status
make[2]: *** [/home/(隐藏)/maplab_ws/devel/lib/libopencv3_catkin.so] Error 1
make[1]: *** [CMakeFiles/opencv3_catkin.dir/all] Error 2
make: *** [all] Error 2
根据链接:Linux提示 /usr/bin/ld:cannot find-lxxx 系列解决方法
安装:
sudo apt-get install libopencv-core-dev
再次编译:
- 2.3.4
Errors << rovio:make /home/(隐藏)/maplab_ws/logs/rovio/build.make.001.log
/home/(隐藏)/maplab_ws/devel/lib/libcv_bridge.so: undefined reference toboost::re_detail::cpp_regex_traits_implementation<char>::transform[abi:cxx11](char const*, char const*) const' /home/(隐藏)/maplab_ws/devel/lib/libcv_bridge.so: undefined reference to
boost::re_detail::cpp_regex_traits_implementation::transform_primary[abi:cxx11](char const*, char const*) const’
collect2: error: ld returned 1 exit status
make[2]: *** [/home/(隐藏)/maplab_ws/devel/lib/rovio/feature_tracker_node] Error 1
make[1]: *** [CMakeFiles/feature_tracker_node.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs…
/home/(隐藏)/maplab_ws/devel/lib/libcv_bridge.so: undefined reference toboost::re_detail::cpp_regex_traits_implementation<char>::transform[abi:cxx11](char const*, char const*) const' /home/(隐藏)/maplab_ws/devel/lib/libcv_bridge.so: undefined reference to
boost::re_detail::cpp_regex_traits_implementation::transform_primary[abi:cxx11](char const*, char const*) const’
collect2: error: ld returned 1 exit status
make[2]: *** [/home/(隐藏)/maplab_ws/devel/lib/rovio/rovio_rosbag_loader] Error 1
make[1]: *** [CMakeFiles/rovio_rosbag_loader.dir/all] Error 2
/home/(隐藏)/maplab_ws/devel/lib/libcv_bridge.so: undefined reference toboost::re_detail::cpp_regex_traits_implementation<char>::transform[abi:cxx11](char const*, char const*) const' /home/(隐藏)/maplab_ws/devel/lib/libcv_bridge.so: undefined reference to
boost::re_detail::cpp_regex_traits_implementation::transform_primary[abi:cxx11](char const*, char const*) const’
collect2: error: ld returned 1 exit status
make[2]: *** [/home/(隐藏)/maplab_ws/devel/lib/rovio/rovio_node] Error 1
make[1]: *** [CMakeFiles/rovio_node.dir/all] Error 2
make: *** [all] Error 2
看上去和boost有关,我怀疑是不是gcc的版本问题,毕竟因为做别的,我在计算机A上安装过好几个版本的gcc,因此做限定:
export CC=/usr/bin/gcc-5
export CXX=/usr/bin/g++-5
再次编译,仍然是相同的错误。此时根据catkin编译的经验,我想删除build devel重新试试,因此运行了:
catkin clean
清除所有build devel log文件夹内容,然后再次使用catkin build maplab编译,解决2.2.1的问题并再次编译,这时神奇的事情发生了,竟然成功了!
使用euroc数据集做了一下测试:Running ROVIOLI in VIO mode,能够正常使用。
2.3 计算机B安装编译过程
经过了2.2节的操作,我推测实际上所需要的操作就是:1. 安装libopencv-core-dev;2. 设置gcc版本。因此在计算机B上做验证。
- 计算机B环境:无GPU,ubuntu 16.04,ROS kinetic,ceres、glog、eigen、protobuf 2.6.1已安装,gcc/g++5
在计算机B上,首先按2.2.3所述安装libopencv-core-dev,因为此系统只有gcc5,因此不用设置gcc版本,一路执行2.1链接【2】中的流程直到catkin build maplab,解决2.2.1的问题,再次编译,此时在计算机B中产生了新的问题:
- 2.3.1
CMake Error at 3rdparty/ippicv/downloader.cmake:73 (file):
file DOWNLOAD HASH mismatch
for file: [/home/(隐藏)/maplab_ws/build/opencv3_catkin/opencv3_src/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/ippicv_linux_20151201.tgz]
expected hash: [808b791a6eac9ed78d32a7666804320e]
actual hash: [fe31652c3413a263d78022d86c7178db]
status: [28;“Timeout was reached”]
这个错误的意思应该是超出了时间限制也没有下载完成,ippicv_linux_20151201.tgz这个文件是不完整的。但是同时,3rdparty/ippicv/downloader.cmake这个文件执行完又自动删除了!所以再次编译就会产生以下错误:
- 2.3.2
CMake Error at cmake/OpenCVFindIPP.cmake:243 (include):
include could not find load file:
/home/(隐藏)/maplab_ws/build/opencv3_catkin/opencv3_src/3rdparty/ippicv/downloader.cmake
Call Stack (most recent call first):
cmake/OpenCVFindLibsPerf.cmake:37 (include)
CMakeLists.txt:558 (include)
找不到3rdparty/ippicv/downloader.cmake这个文件。
此时可以看出,我在计算机B中主要卡在了/maplab_ws/build/opencv3_catkin/opencv3_src/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/ippicv_linux_20151201.tgz,这个压缩包总是下载失败(我推测是网络不稳定,导致计算机A成功了轮到计算机B就老失败)。
这就是为什么我在2.2.2中说将“opencv-3.2.0”文件夹内的内容复制到:
~/maplab_ws/build/opencv3_catkin/opencv3_src 之内对我不起什么作用,因为从https://github.com/Itseez/opencv/archive/3.2.0.zip下载的opencv 3.2的3rdparty/ippicv/也不带ippicv_linux_20151201.tgz,还是得下载!
一个自然的想法是,把计算机A中的ippicv_linux_20151201.tgz移植到计算机B中。需要注意的是,单纯地把ippicv_linux_20151201.tgz放在对应的ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/文件夹内,或者将ippicv_linux_20151201.tgz的内容解压到ippicv/文件夹下是不行的,会报2.3.1类似的错误(注:status: []内容不同)。
所以干脆顺藤摸瓜,把ippicv_linux_20151201.tgz的内容解压到ippicv/文件夹下以后,对OpenCVFindIPP.cmake文件做修改,将243行注释掉:
# include("${OpenCV_SOURCE_DIR}/3rdparty/ippicv/downloader.cmake")
在243行之后添加:
set(OPENCV_ICV_PACKAGE_SUBDIR "/ippicv_lnx")
set(OPENCV_ICV_UNPACK_PATH "${CMAKE_BINARY_DIR}/3rdparty/ippicv")
set(OPENCV_ICV_PATH "${OPENCV_ICV_UNPACK_PATH}${OPENCV_ICV_PACKAGE_SUBDIR}")
set(OPENCV_ICV_PATH "${OPENCV_ICV_PATH}" PARENT_SCOPE)
这主要是因为3rdparty/ippicv/downloader.cmake文件开头写了,该文件负责下载ippicv压缩包,并且返回一个变量的赋值OPENCV_ICV_PATH,所以既然已经解压缩了对应压缩包,把变量赋值在OpenCVFindIPP.cmake里做好,就可以把downloader.cmake注释掉了。
再次编译没有问题,成功编译后,使用euroc数据集做了一下测试:Running ROVIOLI in VIO mode,能够正常使用。
3. 总结
ubuntu 16.04,ROS kinetic,无GPU安装编译maplab过程总结如下(截至2020.12):
按照2.1链接【2】中的过程执行安装,直到catkin build maplab之前;
安装:
sudo apt-get install libopencv-core-dev
设置gcc版本:
export CC=/usr/bin/gcc-5
export CXX=/usr/bin/g++-5
执行一次catkin build maplab,解决2.2.1所述问题;
再次执行catkin build maplab,如果你足够幸运,在此就可以编译成功了;
如果你不幸卡在了下载文件:/maplab_ws/build/opencv3_catkin/opencv3_src/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/ippicv_linux_20151201.tgz (或/maplab_ws/build/opencv3_catkin/opencv3_src/中的其他文件),下载2.1链接【4】带ippicv压缩包的opencv 3.2.0 中的压缩包,解压后把内容复制到/maplab_ws/build/opencv3_catkin/opencv3_src/下(覆盖即可);
将压缩包/maplab_ws/build/opencv3_catkin/opencv3_src/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e/ippicv_linux_20151201.tgz解压缩,把内容(文件夹ippicv_lnx)复制到/maplab_ws/build/opencv3_catkin/opencv3_src/3rdparty/ippicv/路径下;
注释文件/maplab_ws/build/opencv3_catkin/opencv3_src/cmake/OpenCVFindIPP.cmake的第243行:
# include("${OpenCV_SOURCE_DIR}/3rdparty/ippicv/downloader.cmake")
在243行之后添加:
set(OPENCV_ICV_PACKAGE_SUBDIR "/ippicv_lnx")
set(OPENCV_ICV_UNPACK_PATH "${CMAKE_BINARY_DIR}/3rdparty/ippicv")
set(OPENCV_ICV_PATH "${OPENCV_ICV_UNPACK_PATH}${OPENCV_ICV_PACKAGE_SUBDIR}")
set(OPENCV_ICV_PATH "${OPENCV_ICV_PATH}" PARENT_SCOPE)
最后再次执行编译catkin build maplab,即可成功。