项目场景:
SLAMBOOK2 ch6 安装g2o ubuntu22.04-fmt8.1.1
问题描述
/usr/include/spdlog/common.h:127:111: error: ‘basic_runtime’ is not a member of ‘fmt’
127 | std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value>
| ^~~~~~~~~~~~~
/usr/include/spdlog/common.h:127:125: error: template argument 2 is invalid
127 | std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runt
原因分析:
这个错误表明在编译时,spdlog(日志库)无法找到 fmt 库的正确定义。basic_runtime 是 fmt 库的一部分,但是 spdlog 无法识别它。
一种可能的解决方法是确保 spdlog 使用的 fmt 版本是兼容的。有时,版本不匹配可能会导致这样的问题。
解决方案:
重新编译安装fmt8.1.1
更改其cmakelist
添加add_compile_options(-fPIC)
project(FMT CXX)
include(GNUInstallDirs)
set_verbose(FMT_INC_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE STRING
"Installation directory for include files, a relative path that "
"will be joined with ${CMAKE_INSTALL_PREFIX} or an absolute path.")
# Add -fPIC option
add_compile_options(-fPIC)
option(FMT_PEDANTIC "Enable extra warnings and expensive tests." OFF)
option(FMT_WERROR "Halt the compilation with an error on compiler warnings."
OFF)
重新编译
问题解决!