视觉slam十四讲第三方库配置过程遇到的问题及解决过程

视觉slam十四讲第三方库配置过程遇到的问题及解决过程记录

使用环境:Ubuntu22.04

一、配置Ceres时遇到的问题

1.第一个问题:

问题描述

make时报错提示缺少tbb_stddef.h头文件

解决方式

1)cd到路径

/usr/include/tbb

2)创建tbb_stddef.h头文件,通过touch和gedit指令

sudo touch tbb_stddef.h
sudo gedit tbb_stddef.h

3)将博文中的代码复制到打开的文本文件中

tbb_stddef.h源码

4)点击保存后用cmake重新配置

2.第二个问题:

问题描述

由于Eigen版本过新,导致编译过程中,在gtest.h头文件中报错

/home/gatsbychen/programming/slambook2/3rdparty/ceres-solver/internal/ceres/gtest/gtest.h:10445:35: error: variable or field ‘it’ declared void
10445 |   for (typename C::const_iterator it = container.begin();
      |                                   ^~

解决方式

1)从源码下载Eigen3.2.5

下载源码

wget https://gitlab.com/libeigen/eigen/-/archive/3.2.5/eigen-3.2.5.tar.gz

解压缩

tar xzf eigen-3.2.5.tar.gz

2)编译Eigen3.2.5,依次输入以下指令

mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/include/eigen3.2.5 ..
sudo make install

3)修改ceres中查找eigen库的cmake模块,在ceres-solver/cmake文件夹下找到FindEigen.cmake文本文件

输入指令

sudo gedit FindEigen.cmake

将内容替换为

# Ceres Solver - A fast non-linear least squares minimizer
# Copyright 2015 Google Inc. All rights reserved.
# http://ceres-solver.org/
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
#   this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
#   this list of conditions and the following disclaimer in the documentation
#   and/or other materials provided with the distribution.
# * Neither the name of Google Inc. nor the names of its contributors may be
#   used to endorse or promote products derived from this software without
#   specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Author: alexs.mac@gmail.com (Alex Stewart)
#
# FindEigen.cmake - Find Eigen library, version >= 3.
#
# This module defines the following variables:
#
# EIGEN_FOUND: TRUE iff Eigen is found.
# EIGEN_INCLUDE_DIRS: Include directories for Eigen.
#
# EIGEN_VERSION: Extracted from Eigen/src/Core/util/Macros.h
# EIGEN_WORLD_VERSION: Equal to 3 if EIGEN_VERSION = 3.2.0
# EIGEN_MAJOR_VERSION: Equal to 2 if EIGEN_VERSION = 3.2.0
# EIGEN_MINOR_VERSION: Equal to 0 if EIGEN_VERSION = 3.2.0
#
# The following variables control the behaviour of this module:
#
# EIGEN_INCLUDE_DIR_HINTS: List of additional directories in which to
#                          search for eigen includes, e.g: /timbuktu/eigen3.
#
# The following variables are also defined by this module, but in line with
# CMake recommended FindPackage() module style should NOT be referenced directly
# by callers (use the plural variables detailed above instead).  These variables
# do however affect the behaviour of the module via FIND_[PATH/LIBRARY]() which
# are NOT re-called (i.e. search for library is not repeated) if these variables
# are set with valid values _in the CMake cache_. This means that if these
# variables are set directly in the cache, either by the user in the CMake GUI,
# or by the user passing -DVAR=VALUE directives to CMake when called (which
# explicitly defines a cache variable), then they will be used verbatim,
# bypassing the HINTS variables and other hard-coded search locations.
#
# EIGEN_INCLUDE_DIR: Include directory for CXSparse, not including the
#                    include directory of any dependencies.
 
# Called if we failed to find Eigen or any of it's required dependencies,
# unsets all public (designed to be used externally) variables and reports
# error message at priority depending upon [REQUIRED/QUIET/<NONE>] argument.
macro(EIGEN_REPORT_NOT_FOUND REASON_MSG)
  unset(EIGEN_FOUND)
  unset(EIGEN_INCLUDE_DIRS)
  # Make results of search visible in the CMake GUI if Eigen has not
  # been found so that user does not have to toggle to advanced view.
  mark_as_advanced(CLEAR EIGEN_INCLUDE_DIR)
  # Note <package>_FIND_[REQUIRED/QUIETLY] variables defined by FindPackage()
  # use the camelcase library name, not uppercase.
  if (Eigen_FIND_QUIETLY)
    message(STATUS "Failed to find Eigen - " ${REASON_MSG} ${ARGN})
  elseif (Eigen_FIND_REQUIRED)
    message(FATAL_ERROR "Failed to find Eigen - " ${REASON_MSG} ${ARGN})
  else()
    # Neither QUIETLY nor REQUIRED, use no priority which emits a message
    # but continues configuration and allows generation.
    message("-- Failed to find Eigen - " ${REASON_MSG} ${ARGN})
  endif ()
  return()
endmacro(EIGEN_REPORT_NOT_FOUND)
 
# Search user-installed locations first, so that we prefer user installs
# to system installs where both exist.
#
# TODO: Add standard Windows search locations for Eigen.
list(APPEND EIGEN_CHECK_INCLUDE_DIRS
  /usr/eigen3/include/eigen3)
# Additional suffixes to try appending to each search path.
list(APPEND EIGEN_CHECK_PATH_SUFFIXES
  eigen3 # Default root directory for Eigen.
  Eigen/include/eigen3 ) # Windows (for C:/Program Files prefix).
 
# Search supplied hint directories first if supplied.
 
# Mark internally as found, then verify. EIGEN_REPORT_NOT_FOUND() unsets
# if called.
set(EIGEN_FOUND TRUE)
set(EIGEN_INCLUDE_DIR,/usr/include/eigen3.2.5/include/eigen3)
 
 
# This is on a single line s/t CMake does not interpret it as a list of
# elements and insert ';' separators which would result in 3.;2.;0 nonsense.
set(EIGEN_VERSION "3.2.5")
 
 
# Set standard CMake FindPackage variables if found.
if (EIGEN_FOUND)
  set(EIGEN_INCLUDE_DIRS /usr/include/eigen3.2.5/include/eigen3)
endif (EIGEN_FOUND)
 
# Handle REQUIRED / QUIET optional arguments and version.
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Eigen
  REQUIRED_VARS EIGEN_INCLUDE_DIRS
  VERSION_VAR EIGEN_VERSION)
 
# Only mark internal variables as advanced if we found Eigen, otherwise
# leave it visible in the standard GUI for the user to set manually.
if (EIGEN_FOUND)
  mark_as_advanced(FORCE EIGEN_INCLUDE_DIR)
endif (EIGEN_FOUND)

4)用cmake重新编译ceres

二、编译Sophus遇到的问题

1.第一个问题

问题描述

cmake版本低于CMakeLists.txt里的最低版本要求,最低版本要求为3.24.0,而本人使用的版本为3.22.1

解决方式

1)删除原有的cmake

sudo apt remove --purge cmake

2)从官网下载高于3.24.0版本的cmake,如3.25.0

下载

wget https://github.com/Kitware/CMake/releases/download/v3.25.0/cmake-3.25.0.tar.gz

解压

tar -zxvf cmake-3.25.0.tar.gz

3)安装cmake

cd cmake-3.25.0
./bootstrap
make
sudo make install

4)检查cmake版本

cmake --version

若输出3.25.0则为安装成功

2.第二个问题:

问题描述

安装了最新的Sophus库(d0b7315),此时的Sophus使用了模板,需要用到fmt库,而原教程缺少fmt库,因此在make过程会报错

解决方式

1)配置fmt库

git clone https://github.com/fmtlib/fmt.git
cd fmt
mkdir build
cd build
cmake ..
make
sudo make install

2)重新编译构建

3.第三个问题:

问题描述

make时报错如下:

error: invalid ‘static_cast’ from type ‘const ceres::Jet<double, 3>’ to type ‘int319 |     return static_cast<NewType>(x);
      |            ^~~~~~~~~~~~~~~~~~~~~~~

出现的原因可能是ceres版本过新

解决方式

1)安装版本为1.14.x的ceres库

通过指令克隆ceres仓库的1.14.x分支

git clone -b 1.14.x https://github.com/ceres-solver/ceres-solver.git

2)编译构建ceres库,具体过程同上

3)编译构建Sophus库

三、编译ch5源码遇到的问题

问题描述

configure没有问题,make时报错,主要的报错类似下面

/usr/local/include/sophus/types.hpp:234:36: error: ‘enable_if_t’ in namespace ‘std’ does not name a template type

在cppreference.com搜索了一下enable_if_t,发现是C++14新加的using别名

template< bool B, class T = void >
using enable_if_t = typename enable_if<B,T>::type;

解决方式

将ch5的CMakeLists.txt中对C++特性的支持修改为C++14

cmake_minimum_required(VERSION 2.8)

set(CMAKE_BUILD_TYPE "Release")
# 添加c++ 11标准支持 --> 改成c++ 14
set(CMAKE_CXX_FLAGS "-std=c++14 -O2")

# Eigen
include_directories("/usr/include/eigen3")

# 寻找OpenCV库
find_package(OpenCV REQUIRED)
# 添加头文件
include_directories(${OpenCV_INCLUDE_DIRS})

add_subdirectory(imageBasics)
add_subdirectory(stereo)
add_subdirectory(rgbd)

重新编译构建后,即可顺利运行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hunnybub

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值