In file included from /usr/include/spdlog/spdlog.h:12, from /home/lu/Downloads/rune_ku/g2o-master/g2o/stuff/logger.h:34, from /home/lu/Downloads/rune_ku/g2o-master/g2o/stuff/timeutil.cpp:31: /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_runtime<Char>>::value> | ^~~~ /usr/include/spdlog/common.h:127:138: error: expected ‘{’ before ‘>’ token 127 | std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value> | ^ In file included from /usr/include/spdlog/spdlog.h:12, from /home/lu/Downloads/rune_ku/g2o-master/g2o/stuff/logger.h:34, from /home/lu/Downloads/rune_ku/g2o-master/g2o/stuff/logger.cpp:27: /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_runtime<Char>>::value> | ^~~~ /usr/include/spdlog/common.h:127:138: error: expected ‘{’ before ‘>’ token 127 | std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value> | ^ In file included from /usr/include/spdlog/spdlog.h:12, from /home/lu/Downloads/rune_ku/g2o-master/g2o/stuff/logger.h:34, from /home/lu/Downloads/rune_ku/g2o-master/g2o/stuff/property.cpp:32: /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_runtime<Char>>::value> | ^~~~ /usr/include/spdlog/common.h:127:138: error: expected ‘{’ before ‘>’ token 127 | std::is_convertible<T, fmt::basic_string_view<Char>>::value || std::is_same<remove_cvref_t<T>, fmt::basic_runtime<Char>>::value> | ^ make[2]: *** [g2o/stuff/CMakeFiles/stuff.dir/build.make:79: g2o/stuff/CMakeFiles/stuff.dir/timeutil.cpp.o] Error 1 make[2]: *** Waiting for unfinished jobs.... make[2]: *** [g2o/stuff/CMakeFiles/stuff.dir/build.make:191: g2o/stuff/CMakeFiles/stuff.dir/logger.cpp.o] Error 1 make[2]: *** [g2o/stuff/CMakeFiles/stuff.dir/build.make:149: g2o/stuff/CMakeFiles/stuff.dir/property.cpp.o] Error 1 [ 6%] Linking CXX shared library ../../../../../lib/libg2o_parser.so [ 6%] Built target parser_library [ 6%] Building CXX object g2o/examples/interactive_slam/slam_parser/interface/CMakeFiles/interface_library.dir/parser_interface.cpp.o [ 6%] Building CXX object g2o/examples/interactive_slam/slam_parser/interface/CMakeFiles/interface_library.dir/slam_context_interface.cpp.o [ 7%] Linking CXX shared library ../../../../../lib/libg2o_interface.so [ 7%] Built target interface_library make[1]: *** [CMakeFiles/Makefile2:1422: g2o/stuff/CMakeFiles/stuff.dir/all] Error 2 make: *** [Makefile:156: all] Error 2
时间: 2025-08-04 18:57:02 浏览: 9
<think>嗯,用户遇到了在Ubuntu22.04编译g2o时出现的'basic_runtimeisnotamemberoffmt'错误,这看起来是spdlog和fmt库版本冲突问题。从用户引用的[1]来看,ta正在尝试安装SLAMBOOK2ch6所需的g2o环境,而且错误信息明确指向了fmt库的API变动。用户应该是在系统里同时存在多个fmt版本:可能是通过apt安装的系统版本(8.1.1)和g2o要求的版本(8.0.x或更早)不兼容。spdlog的common.h文件里引用了fmt::basic_runtime,这个类似乎在fmt8.1中被移除了。考虑到SLAMBOOK2的代码较旧,确实可能依赖旧版fmt。我之前给的解决方案需要更细致些:强制g2o使用自带的fmt子模块是关键。用户可能在第一次编译时没启用BUILD_MANUAL选项导致子模块未初始化。另外注意到引用[5]显示ta最终编译成功了SLAMBOOK2,说明问题集中在g2o的依赖管理上。需要提醒用户彻底清理之前的编译痕迹(特别是build目录),否则cmake缓存可能保留错误路径。Ubuntu22.04的默认Eigen库版本(3.4.0)应该兼容,重点还是解决fmt冲突。如果用户后续遇到显示问题(类似引用[2]的OpenCVGUI错误),建议ta单独处理——不过当前优先解决编译问题。用户没有提供具体操作环境细节,但考虑到是SLAM开发,大概率在用WSL或原生Ubuntu。可以补充说明:如果是WSL环境,glvnd相关依赖可以跳过。</think>
要解决在Ubuntu 22.04上编译g2o时出现的`‘basic_runtime’ is not a member of ‘fmt’`错误,请按照以下步骤操作:
### 解决方案步骤
1. **卸载冲突的fmt库**
系统安装的fmt-8.1.1与g2o不兼容:
```bash
sudo apt remove libfmt-dev -y
```
2. **强制g2o使用子模块中的fmt**
进入g2o源码目录后修改CMake配置:
```bash
cd g2o
# 修改CMake配置
sed -i 's/find_package(fmt QUIET)/set(HAVE_FMT_BASIC_RUNTIME ON)/g' CMakeLists.txt
sed -i 's/find_package(spdlog QUIET)/#find_package(spdlog QUIET)/g' CMakeLists.txt
```
3. **编译安装兼容的fmt库**
g2o需要较低版本fmt(<=8.0.1):
```bash
git clone https://github.com/fmtlib/fmt.git
cd fmt
git checkout 8.0.1
mkdir build && cd build
cmake -DCMAKE_POSITION_INDEPENDENT_CODE=TRUE ..
make -j$(nproc)
sudo make install
```
4. **重新编译g2o**
启用fmt子模块并禁用冲突组件:
```bash
cd g2o
mkdir -p build && cd build
cmake .. \
-DBUILD_WITH_MARCH_NATIVE=ON \
-DG2O_USE_OPENGL=OFF \
-DBUILD_SHARED_LIBS=ON \
-DFMT_INCLUDE_DIR=/usr/local/include \
-DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
sudo make install
sudo ldconfig # 刷新库链接
```
5. **验证安装**
创建测试程序:
```cpp
// test_g2o.cpp
#include <g2o/core/sparse_optimizer.h>
int main() {
g2o::SparseOptimizer optimizer;
return 0;
}
```
编译运行:
```bash
g++ test_g2o.cpp -o test -lg2o_core -lg2o_stuff
./test # 无报错即成功
```
### 原理说明
错误由fmt版本冲突引起:
- **fmt-8.1.1** 移除了`basic_runtime`类型定义[^1]
- SLAMBOOK2使用的g2o版本依赖 **fmt<=8.0.1** 的API接口
- 强制使用低版本fmt避开接口变更兼容性问题[^5]
阅读全文
相关推荐




















