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})