【无标题】Ubuntu22.04编译视觉十四讲slambook2 ch4时fmt库的报错
Ubuntu22.04编译视觉十四讲slambook2 ch4时fmt库的报错
cmake ..顺利,make后出现如下报错:
in function `std::make_unsigned<int>::type fmt::v8::detail::to_unsigned<int>(int)':
trajectoryError.cpp:(.text._ZN3fmt2v86detail11to_unsignedIiEENSt13make_unsignedIT_E4typeES4_[_ZN3fmt2v86detail11to_unsignedIiEENSt13make_unsignedIT_E4typeES4_]+0x23): undefined reference to `fmt::v8::detail::assert_fail(char const*, int, char const*)'
重点:undefined reference to ‘fmt::v8::XXX)’
这个错误是链接阶段的错误,表明在链接时找不到 fmt::v8::detail::assert_fail 这个符号,通常与 fmt 库的使用或链接设置有关。
检查CMakeLists.txt
外面那个CMakeLists.txt没有,example文件夹下面的CMakeLists.txt有 fmt
option(USE_UBUNTU_20 "Set to ON if you are using Ubuntu 20.04" OFF)
find_package(Pangolin REQUIRED)
if(USE_UBUNTU_20)
message("You are using Ubuntu 20.04, fmt::fmt will be linked")
find_package(fmt REQUIRED)
set(FMT_LIBRARIES fmt::fmt)
endif()
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(trajectoryError trajectoryError.cpp)
target_link_libraries(trajectoryError ${Pangolin_LIBRARIES} ${FMT_LIBRARIES})
这里是使用ubuntu20.04才会进入if里面执行:
查找 fmt 库(fmt 是一个现代的格式化库,用于 C++ 格式化输出。)
设置 FMT_LIBRARIES 变量为 fmt::fmt,它指的是 fmt 库的 CMake 目标名称
把内容修改成下面这样:
# option(USE_UBUNTU_20 "Set to ON if you are using Ubuntu 20.04" OFF)
find_package(Pangolin REQUIRED)
# if(USE_UBUNTU_20)
# message("You are using Ubuntu 20.04, fmt::fmt will be linked")
# find_package(fmt REQUIRED)
# set(FMT_LIBRARIES fmt::fmt)
# endif()
find_package(fmt REQUIRED)
set(FMT_LIBRARIES fmt::fmt)
include_directories(${Pangolin_INCLUDE_DIRS})
add_executable(trajectoryError trajectoryError.cpp)
target_link_libraries(trajectoryError ${Pangolin_LIBRARIES} ${FMT_LIBRARIES})