ubuntu20.04 编译orb-slam3踩坑

系统配置

ubuntu20.04
opencv 3.4.15
eigen 3.3.1
pangolin

编译过程遇到的错误

1

只展示部分:

/usr/local/include/sigslot/signal.hpp:109:79: error: ‘decay_t’ is not a member of ‘std’; did you mean ‘decay’?
  109 | constexpr bool is_weak_ptr_compatible_v = detail::is_weak_ptr_compatible>::value;
      |                                                                               ^~~~~~~
      |                                                                               decay
/usr/local/include/sigslot/signal.hpp:109:79: error: ‘decay_t’ is not a member of ‘std’; did you mean ‘decay’?
  109 | constexpr bool is_weak_ptr_compatible_v = detail::is_weak_ptr_compatible>::value;
      |                                                                               ^~~~~~~
      |                                                                               decay
/usr/local/include/sigslot/signal.hpp:109:87: error: template argument 1 is invalid
  109 | constexpr bool is_weak_ptr_compatible_v = detail::is_weak_ptr_compatible>::value;
      |                                                                                       ^
/usr/local/include/sigslot/signal.hpp:109:92: error: ‘::value’ has not been declared
  109 | constexpr bool is_weak_ptr_compatible_v = detail::is_weak_ptr_compatible>::value;
      |                                                                                            ^~~~~
/usr/local/include/sigslot/signal.hpp:132:53: error: ‘remove_pointer_t’ is not a member of ‘std’; did you mean ‘remove_pointer’?
  132 |                                                std::remove_pointer_t>::value;
      |                                                     ^~~~~~~~~~~~~~~~
      |                                                     remove_pointer

decay
这个的问题出在于编译器的问题,原作者使用的是C++11编译的,从CMakeLists.txt前面几行可以看出,换用C++14可以解决该问题。
有两种方法可以改进:
(1) 终端命令,不必改CMakeLists.txt
可以在终端使用命令

sed -i 's/++11/++14/g' CMakeLists.txt

注: 命令后面的CMakeLists.txt需要在代码根目录下使用

(2)修改CMakeLists.txt

将下面的代码注释掉(或者删掉)

# Check C++11 or C++0x support
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
   add_definitions(-DCOMPILEDWITHC11)
   message(STATUS "Using flag -std=c++14.")
elseif(COMPILER_SUPPORTS_CXX0X)
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
   add_definitions(-DCOMPILEDWITHC0X)
   message(STATUS "Using flag -std=c++0x.")
else()
   message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++14 support. Please use a different C++ compiler.")
endif()

改为

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS OFF)
add_definitions(-DCOMPILENDWITHC11)

2 有选择地编译例程

打算试试RGB-D加惯性的slam程序,结果报错:

/home/********/ORB_SLAM3-master/Examples/RGB-D-Inertial/rgbd_inertial_realsense_D435i.cc:351:26: error: ‘std::chrono::monotonic_clock’ has not been declared
  351 |             std::chrono::monotonic_clock::time_point time_Start_Process = std::chrono::monotonic_clock::now();

这是因为C++版本不同导致的系统计时函数编译报错
解决方案是 搜索COMPILEDWITHC11
然后把
monotonic_clock 换成 steady_clock
例如:

/*
#ifdef COMPILEDWITHC11
            std::chrono::steady_clock::time_point time_Start_Process = std::chrono::steady_clock::now();
#else
            std::chrono::monotonic_clock::time_point time_Start_Process = std::chrono::monotonic_clock::now();
#endif
*/
// 替换成下面的:
	std::chrono::steady_clock::time_point time_Start_Process = std::chrono::steady_clock::now();//修改替换的代码部分

3 自己编写ROS节点程序遇见的问题

/usr/local/include/sigslot/signal.hpp:109:79: error: ‘decay_t’ is not a member of ‘std’; did you mean ‘decay’?
  109 | _weak_ptr_compatible_v = detail::is_weak_ptr_compatible>::value;

这个依旧是C++编译器版本的问题, 设置成C++14即可

/usr/local/include/pangolin/gl/gl.hpp:334:5: error: ‘glCopyImageSubDataNV’ was not declared in this scope
  334 |     glCopyImageSubDataNV(tex.tid, GL_TEXTURE_2D, 0, 0, 0, 0,

需要在target_link_librariess上加上pangolin

你可能感兴趣的:(视觉惯性导航,ROS,opencv,c++,人工智能)