开源ORB_SLAM2项目编译常见问题与应对办法

发布于:2025-03-22 ⋅ 阅读:(55) ⋅ 点赞:(0)

 问题1来源:


报错如下:

/usr/local/include/sigslot/signal.hpp: In member function ‘const void* sigslot::detail::slot_pmf<Pmf, Ptr, Args>::get_object() const’:
/usr/local/include/sigslot/signal.hpp:935:31: error: ‘ptr’ was not declared in this scope
         return get_object_ptr(ptr);
                               ^~~
/usr/local/include/sigslot/signal.hpp:935:31: note: suggested alternative: ‘Ptr’
         return get_object_ptr(ptr);
                               ^~~
                               Ptr
/usr/local/include/sigslot/signal.hpp: In member function ‘const std::type_info& sigslot::detail::slot_pmf<Pmf, Ptr, Args>::get_callable_type() const’:
/usr/local/include/sigslot/signal.hpp:940:23: error: ‘pmf’ was not declared in this scope
         return typeid(pmf);
                       ^~~
/usr/local/include/sigslot/signal.hpp:793:10: error: ‘enable_if_t’ in namespace ‘std’ does not name a template type
     std::enable_if_t<function_traits<C>::must_check_object, bool>

问题分析:

sigslot 库在编译时出现了一些 作用域解析C++ 标准支持 相关的问题,可能的原因有:

  1. ptrpmf 变量未在作用域内

    • 可能是 sigslot 代码中的 成员变量名拼写错误C++ 标准支持不兼容

    • 例如 ptr 应该是 this->ptr,或者 pmf 应该是 this->pmf

  2. std::enable_if_t 不被识别

    • 说明编译器可能不支持 C++14 或更高版本,因为 std::enable_if_tC++14 引入的特性。

解决方案:

1. 检查 C++ 标准

首先,确保 CMakeLists.txt 或 Makefile 启用了 C++14 或更高版本

Cmakelist配置修改版本(部分):

cmake_minimum_required(VERSION 2.8)
project(ORB_SLAM2)

IF(NOT CMAKE_BUILD_TYPE)
  SET(CMAKE_BUILD_TYPE Release)
ENDIF()

MESSAGE("Build type: " ${CMAKE_BUILD_TYPE})

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  -Wall   -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall   -O3")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -march=native")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native")

set(CMAKE_CXX_STANDARD 14)
add_definitions(-DCOMPILEDWITHC11)

 问题2来源:

报错如下:

CMake Error at components/pango_python/CMakeLists.txt:9 (find_package):
  By not providing "FindPython3.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Python3", but
  CMake did not find one.

  Could not find a package configuration file provided by "Python3" with any
  of the following names:

    Python3Config.cmake
    python3-config.cmake

  Add the installation prefix of "Python3" to CMAKE_PREFIX_PATH or set
  "Python3_DIR" to a directory containing one of the above files.  If
  "Python3" provides a separate development package or SDK, be sure it has
  been installed.
Call Stack (most recent call first):
  CMakeLists.txt:124 (include)

问题分析:

  1. Python3 未安装或 CMake 无法找到 Python3

    • 系统可能没有安装 Python3,或者 Python3 的开发工具包(如 python3-dev)未安装。

  2. Python3 的 CMake 配置文件 (Python3Config.cmake) 位置不在 CMake 默认搜索路径中

    • 可能 Python3 通过 pyenvconda 安装,CMake 需要手动指定 Python3 目录。

解决方案:

CMake 版本太旧(推荐 CMake 3.18+,因为较早版本的 CMake 可能不支持 find_package(Python3))。

tar -zxvf cmake-3.25.3-linux-x86_64.tar.gz
sudo mv cmake-3.25.3-linux-x86_64 /opt/cmake-3.25.3
sudo ln -sf /opt/cmake-3.25.3/bin/* /usr/bin/

 问题3来源:

报错如下:

cc1plus: error: unrecognized command line option ‘-Wno-null-pointer-subtraction’ [-Werror]
cc1plus: error: unrecognized command line option ‘-Wno-null-pointer-arithmetic’ [-Werror]
cc1plus: all warnings being treated as errors
CMakeFiles/pango_vars.dir/build.make:89: recipe for target 'CMakeFiles/pango_vars.dir/components/pango_vars/src/varstate.cpp.o' failed
make[2]: *** [CMakeFiles/pango_vars.dir/components/pango_vars/src/varstate.cpp.o] Error 1
CMakeFiles/Makefile2:757: recipe for target 'CMakeFiles/pango_vars.dir/all' failed
make[1]: *** [CMakeFiles/pango_vars.dir/all] Error 2
make[1]: *** 正在等待未完成的任务....

问题分析:

编译错误是由于 GCC 版本过低不支持 -Wno-null-pointer-subtraction-Wno-null-pointer-arithmetic 选项。这些选项是较新的编译器(GCC 7 及以上)才支持的。如果 GCC 版本较低,就会报错 unrecognized command line option

解决方案:

方法一:

sudo apt update
sudo apt install gcc g++

 方法二:
如果升级 GCC 仍然无法解决,可以手动去掉 -Wno-null-pointer-subtraction-Wno-null-pointer-arithmetic 这两个编译选项。在 CMakeLists.txtCXX_FLAGS 相关部分查找这两个选项,并删除它们:

-Wno-null-pointer-subtraction
-Wno-null-pointer-arithmetic

 问题4来源:

报错如下:

/home/wheeltec-client/ORB_SLAM2-master/src/Viewer.cc:160:17: error: ‘usleep’ was not declared in this scope
                 usleep(3000);

问题分析:

usleep 在某些 C++ 标准(如 C++11 及更新版本)中可能未被默认包含。你可以尝试以下几种方法修复这个问题:

解决方案:

包含正确的头文件,usleep 需要包含 <unistd.h> 头文件。请确保在 Viewer.cc 文件顶部添加:

#include <unistd.h>

 问题5来源:

报错如下:

[ 62%] Linking CXX shared library /home/wheeltec-client/ORB_SLAM2-master/lib/libORB_SLAM2.so
/usr/bin/ld: 找不到 -lEigen3::Eigen
collect2: error: ld returned 1 exit status
CMakeFiles/ORB_SLAM2.dir/build.make:445: recipe for target '/home/wheeltec-client/ORB_SLAM2-master/lib/libORB_SLAM2.so' failed
make[2]: *** [/home/wheeltec-client/ORB_SLAM2-master/lib/libORB_SLAM2.so] Error 1
CMakeFiles/Makefile2:94: recipe for target 'CMakeFiles/ORB_SLAM2.dir/all' failed
make[1]: *** [CMakeFiles/ORB_SLAM2.dir/all] Error 2
Makefile:90: recipe for target 'all' failed
make: *** [all] Error 2

问题分析:

CMake 找不到 Eigen,手动指定路径.

解决方案:
删除原cmake_modules的find文件,有问题。

 运行效果:

总结


编译过程主要还是各个库版本的适配问题,源代码逻辑大概率不会错,除了为了版本的适配做修改。