1. 报错
在编译高博的视觉SLAM第7讲的ch7/pose_estimation_3d2d.cpp
时,出现错误:
/usr/local/include/g2o/core/base_fixed_sized_edge.h:192:32: error: ‘index_sequence’ is not a member of ‘std’
struct HessianTupleType<std::index_sequence<Ints...>> {
^~~~~~~~~~~~~~
/usr/local/include/g2o/core/base_fixed_sized_edge.h:192:32: error: ‘index_sequence’ is not a member of ‘std’
/usr/local/include/g2o/core/base_fixed_sized_edge.h:192:51: error: expected parameter pack before ‘...’
2. 原因
视觉SLAM书上的程序使用的g2o
版本比较旧了,使用的是c++11
版本的g20。而自己在编译g2o的时候编译的是最新版本的g2o,里面大量使用了c++14标准库
的一些新特性,比如std::index_sequence
等等。而书上的CMakeLists.txt
默认使用的是c++11
进行cmake编译,所以报错。
3. 解决方案
让CMake编译在C++14标准下进行,在CMakeLists.txt添加:
set(CMAKE_CXX_STANDARD 14)
另外安装了最新的g2o进行编译可能还会出现fmt::v8
的链接错误:
CMakeFiles/pose_estimation_3d2d.dir/pose_estimation_3d2d.cpp.o: In function `fmt::v8::appender fmt::v8::detail::write<char, fmt::v8::appender>(fmt::v8::appender, fmt::v8::basic_string_view<fmt::v8::type_i
dentity<char>::type>, fmt::v8::basic_format_specs<char> const&, fmt::v8::detail::locale_ref) [clone .isra.1451]':
pose_estimation_3d2d.cpp:(.text+0x490c): undefined reference to `fmt::v8::detail::throw_format_error(char const*)'
CMakeFiles/pose_estimation_3d2d.dir/pose_estimation_3d2d.cpp.o: In function `unsigned long long fmt::v8::detail::width_checker<fmt::v8::detail::error_handler>::operator()<float, 0>(float) [clone .isra.384
]':
相应的解决方案在这里。其实就是编译fmt的相关库并且链接到可执行程序上。