视觉SLAM十四讲 报错ch13 问题汇总 /usr/bin/ld: /usr/local/lib/libfmt.a(format.cc.o)
視覺SLAM十四講 報(bào)錯(cuò)ch13 /usr/bin/ld: /usr/local/lib/libfmt.a
- 1. 問題1:未鏈接fmt庫
- 1.1 解決方案
- 2. 問題2:-fPIC
- 2.1 解決方案
本文總結(jié)高博視覺SLAM十四講第13講demo程序編譯會(huì)出現(xiàn)的問題。注意不包括由于Eigen庫、OpenCV庫沒安裝好的問題。
1. 問題1:未鏈接fmt庫
[ 93%] Linking CXX executable ../bin/run_kitti_stereo ../lib/libmyslam.so: undefined reference to `std::locale fmt::v8::detail::locale_ref::get<std::locale>() const' ../lib/libmyslam.so: undefined reference to `fmt::v8::detail::assert_fail(char const*, int, char const*)' ../lib/libmyslam.so: undefined reference to `fmt::v8::vprint(fmt::v8::basic_string_view<char>, fmt::v8::b asic_format_args<fmt::v8::basic_format_context<fmt::v8::appender, char> >)'這個(gè)錯(cuò)誤的意思是編譯demo中的libmyslam.so鏈接文件時(shí),使用了fmt::v8作用域下的函數(shù)卻沒有鏈接fmt的庫,導(dǎo)致undefined reference。
1.1 解決方案
安裝fmt庫參照CSSDCC博客。值得注意的是有些人在編譯視覺SLAM十四講的任意一個(gè)demo都不會(huì)出現(xiàn)有關(guān)于fmt的問題,是因?yàn)闀旧纤褂玫膅2o版本比較舊了,而我們自己在安裝g2o通常是在https://github.com/RainerKuemmerle/g2o上拉最新的程序并編譯使用。新版的g2o使用了C++14、fmt::v8,而書中demo是C++11且沒有fmt。所以才會(huì)出現(xiàn)相關(guān)錯(cuò)誤,參照:
- 視覺SLAM十四講 報(bào)錯(cuò) error: ‘index_sequence’ is not a member of ‘std‘
- 視覺SLAM十四講 報(bào)錯(cuò)In function `fmt::v8::detail::error_handler::on_error(char const*)‘
在ch13這里的解決辦法是,將libmyslam.so鏈接fmt。ch13/src/CMakeLists.txt:
target_link_libraries(myslam${THIRD_PARTY_LIBS}fmt::fmt # 加入這一行)2. 問題2:-fPIC
[ 75%] Linking CXX shared library ../lib/libmyslam.so /usr/bin/ld: /usr/local/lib/libfmt.a(format.cc.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC _2.2.5' can not be used when making a shared object; recompile with -fPIC /usr/bin/ld: final link failed: Bad value collect2: error: ld returned 1 exit status src/CMakeFiles/myslam.dir/build.make:396: recipe for target 'lib/libmyslam.so' failed make[2]: *** [lib/libmyslam.so] Error 1 CMakeFiles/Makefile2:85: recipe for target 'src/CMakeFiles/myslam.dir/all' failed make[1]: *** [src/CMakeFiles/myslam.dir/all] Error 2 Makefile:94: recipe for target 'all' failed make: *** [all] Error 2具體原因參照博客https://blog.csdn.net/npu_wy/article/details/38589499。這里給出解決方案
2.1 解決方案
正如編譯報(bào)錯(cuò)中所說的:
…can not be used when making a shared object; recompile with -fPIC
我們將fmt重新編譯,并且在編譯fmt之前,在其CMakeLists.txt中加入:
add_compile_options(-fPIC)再執(zhí)行:
mkdir build cd build cmake .. make -j8 sudo make install編譯成功。
總結(jié)
以上是生活随笔為你收集整理的视觉SLAM十四讲 报错ch13 问题汇总 /usr/bin/ld: /usr/local/lib/libfmt.a(format.cc.o)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2022年二建《市政》科目答案已出,请收
- 下一篇: 情迁机器人Tim_情迁QQ机器人1.8.