1. 找不到g2o庫!在CMakeLists.txt中使用指令 message(STATUS "${G2O_FOUND}") 打印結果爲NO。html
問題描述:bash
CMakeLists.txt 中採用以下命令尋找g2o庫。架構
# g2o
find_package( G2O REQUIRED )
include_directories( ${G2O_INCLUDE_DIRS} )
科普時間:find_package() 會在模塊路徑中尋找FindNAME.cmake文件,再經由此文件尋找庫全部文件,包括頭文件,靜態庫(*.a),動態庫(*.so),這種查找方法稱爲模塊模式。更多詳情參考此連接。ui
因爲我把g2o安裝在 /usr/local/g2o 路徑中,不在FindNAME.cmake的默認查找路徑中,所以一直找不到。spa
解決方法:.net
在CMakeLists.txt中進行修改,以下所示,命令行
set(CMAKE_PREFIX_PATH "/usr/local/g2o") find_package( G2O REQUIRED ) message(STATUS "${G2O_INCLUDE_DIR}") include_directories( ${G2O_INCLUDE_DIR} )
同時在FindG2O.cmake中,將 NO_DEFAULT_PATH 註釋掉。以下所示,3d
FIND_PATH(G2O_INCLUDE_DIR g2o/core/base_vertex.h ${G2O_ROOT}/include $ENV{G2O_ROOT}/include /usr/local/include ... #NO_DEFAULT_PATH )
若是指定了NO_DEFAULT_PATH選項,全部NO_*選項都會被激活,致使 set(CMAKE_PREFIX_PATH "/usr/local/g2o") 設置的路徑被跳過。code
2. 運行make進行編譯時,出現以下報錯,htm
/usr/bin/ld: cannot find -lg2o_core /usr/bin/ld: cannot find -lg2o_stuff /usr/bin/ld: cannot find -lg2o_types_slam3d
問題描述:
編譯執行文件時使用 target_link_libraries() 連接上述三個動態庫文件,在 /usr/local/g2o/lib 中能夠找到這些文件,從報錯能夠判斷應該是找不到正確的連接路徑。
解決方法:
在CMakeList.txt中添加以下命令行,設置動態庫所在的絕對路徑。
link_directories("/usr/local/g2o/lib")
關於在cmake中添加頭文件目錄,連接動態庫、靜態庫的操做參考這個連接。
3. 運行make編譯代碼,報錯以下,
/home/gordon/kalibr_ws/devel/lib/libcholmod.a(cholmod_super_numeric.o): In function `cholmod_super_numeric': cholmod_super_numeric.c:(.text+0xe78): undefined reference to `dsyrk_' cholmod_super_numeric.c:(.text+0xf76): undefined reference to `dgemm_' cholmod_super_numeric.c:(.text+0x129c): undefined reference to `dpotrf_' cholmod_super_numeric.c:(.text+0x13a2): undefined reference to `dtrsm_' cholmod_super_numeric.c:(.text+0x1dd6): undefined reference to `zherk_' cholmod_super_numeric.c:(.text+0x1ed4): undefined reference to `zgemm_' cholmod_super_numeric.c:(.text+0x2286): undefined reference to `zpotrf_' cholmod_super_numeric.c:(.text+0x23b2): undefined reference to `ztrsm_' cholmod_super_numeric.c:(.text+0x2dcb): undefined reference to `zherk_' cholmod_super_numeric.c:(.text+0x2ec9): undefined reference to `zgemm_' cholmod_super_numeric.c:(.text+0x325c): undefined reference to `zpotrf_' cholmod_super_numeric.c:(.text+0x337c): undefined reference to `ztrsm_' /home/gordon/kalibr_ws/devel/lib/libcholmod.a(cholmod_super_solve.o): In function `cholmod_super_lsolve': cholmod_super_solve.c:(.text+0x548): undefined reference to `ztrsm_' cholmod_super_solve.c:(.text+0x5f2): undefined reference to `zgemm_' cholmod_super_solve.c:(.text+0x876): undefined reference to `dtrsm_' cholmod_super_solve.c:(.text+0x91d): undefined reference to `dgemm_' cholmod_super_solve.c:(.text+0xad0): undefined reference to `dtrsv_' cholmod_super_solve.c:(.text+0xb5c): undefined reference to `dgemv_' cholmod_super_solve.c:(.text+0xcc6): undefined reference to `ztrsv_' cholmod_super_solve.c:(.text+0xd55): undefined reference to `zgemv_' /home/gordon/kalibr_ws/devel/lib/libcholmod.a(cholmod_super_solve.o): In function `cholmod_super_ltsolve': cholmod_super_solve.c:(.text+0x133b): undefined reference to `zgemm_' cholmod_super_solve.c:(.text+0x13c9): undefined reference to `ztrsm_' cholmod_super_solve.c:(.text+0x169a): undefined reference to `dgemm_' cholmod_super_solve.c:(.text+0x1721): undefined reference to `dtrsm_' cholmod_super_solve.c:(.text+0x18bf): undefined reference to `dgemv_' cholmod_super_solve.c:(.text+0x1912): undefined reference to `dtrsv_' cholmod_super_solve.c:(.text+0x1a9d): undefined reference to `zgemv_' cholmod_super_solve.c:(.text+0x1af7): undefined reference to `ztrsv_'
問題描述:
由報錯第一行能夠斷定該報錯與Cholmod庫有關。沒法正確連接Cholmod庫。
查看cmake輸出內容,以下所示,
Found CHOLMOD: /home/gordon/kalibr_ws/devel/include/suitesparse
能夠肯定尋找cholmod庫的結果是suitesparse庫(目前不清楚這兩個庫的關係,先將它們等同起來)。我以前在kalibr_ws中安裝了suitesparse庫,同時,g2o的readme.md也讓我在根目錄下安裝了suitesparse庫。想到kalibr_ws是採用catkin_build編譯的,其架構跟cmake一定不一致,所以嘗試換成根目錄下的庫。
解決方法:
在 ~/.bashrc 中去除kalibr_ws的環境變量,重啓終端。可經過 echo $PATH 命令查看該環境變量是否被移除。或者,暫時將kalibr_ws中的devel文件夾暫時移除。使用 cmake 從新連接庫文件,獲得以下結果,
Found CHOLMOD: /usr/include/suitesparse
至此便可編譯成功。