Cartographer编译方法及编译出错(glog库链接错误)解决方法

最近在重新调试Carto代码,想把自己的代码加入到Carto中,原本想在IDE中调试,然而Carto编译方式比较奇葩(

catkin_make_isolated --install --use-ninja)试了Clion、VScode、Qt(ros版)编译都会出问题。

不过Clion讲道理应该是可以编译的,不过要安装插件,由于我的版本太低了,就放弃了。具体参考https://github.com/larics/cartographer_superbuild。

最后只能在命令行编译,使用glog将中间变量值保存下来用来调试,有更好的调试方法的小伙伴可以留言~

按照官网步骤按照完成好Carto,参考

https://google-cartographer-ros.readthedocs.io/en/latest/compilation.html

编译完成并没有报错,然而在跑例程的时候节点会直接死掉

roslaunch cartographer_ros offline_backpack_2d.launch bag_filenames:=/home/le/b2-2016-04-05-14-44-52.bag 
... logging to /home/le/.ros/log/b7666ebc-0b88-11ea-a0d3-1831bf0f22e1/roslaunch-God-9181.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://localhost:41953/

SUMMARY
========

PARAMETERS
 * /rosdistro: kinetic
 * /rosversion: 1.12.14
 * /use_sim_time: True

NODES
  /
    cartographer_occupancy_grid_node (cartographer_ros/cartographer_occupancy_grid_node)
    cartographer_offline_node (cartographer_ros/cartographer_offline_node)
    rviz (rviz/rviz)

ROS_MASTER_URI=http://localhost:11311

WARNING: Package name "GNSS_INS" does not follow the naming conventions. It should start with a lower case letter and only contain lower case letters, digits, underscores, and dashes.
process[rviz-1]: started with pid [9198]
process[cartographer_occupancy_grid_node-2]: started with pid [9199]
process[cartographer_offline_node-3]: started with pid [9200]
/home/le/cartographer/install_isolated/lib/cartographer_ros/cartographer_offline_node: symbol lookup error: /home/le/cartographer/install_isolated/lib/cartographer_ros/cartographer_offline_node: undefined symbol: _ZN6google7LogSink8ToStringB5cxx11EiPKciPK2tmS2_mi
[cartographer_offline_node-3] process has died [pid 9200, exit code 127, cmd /home/le/cartographer/install_isolated/lib/cartographer_ros/cartographer_offline_node -configuration_directory /home/le/cartographer/install_isolated/share/cartographer_ros/configuration_files -configuration_basenames backpack_2d.lua -urdf_filenames /home/le/cartographer/install_isolated/share/cartographer_ros/urdf/backpack_2d.urdf -bag_filenames /home/le/b2-2016-04-05-14-44-52.bag echoes:=horizontal_laser_2d __name:=cartographer_offline_node __log:=/home/le/.ros/log/b7666ebc-0b88-11ea-a0d3-1831bf0f22e1/cartographer_offline_node-3.log].
log file: /home/le/.ros/log/b7666ebc-0b88-11ea-a0d3-1831bf0f22e1/cartographer_offline_node-3*.log

其中symbol lookup error表示没有链接到指定库上,然而查看多次都可以看见已经安装了glog库

又重新将Carto编译了一遍,然后在编译过程中出现如下失败,但是编译可以通过,之前并没有发现

 Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
-- Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
-- Performing Test GFLAGS_IN_GOOGLE_NAMESPACE
-- Performing Test GFLAGS_IN_GOOGLE_NAMESPACE - Success
-- Found Gflags: /usr/include  
-- Found Google Flags header in: /usr/include, in namespace: google
-- No preference for use of exported glog CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported glog CMake configuration if available.
-- Failed to find installed glog CMake configuration, searching for glog build directories exported with CMake.
-- Failed to find an installed/exported CMake configuration for glog, will perform search for installed glog components.
-- Found Glog: /usr/local/include  
-- Found Google Log (glog). Assuming glog was built with gflags support as gflags was found. This will make gflags a public dependency of Ceres.
-- Building with OpenMP.
-- Performing Test COMPILER_HAS_CXX11_FLAG
-- Performing Test COMPILER_HAS_CXX11_FLAG - Success
-- Looking for C++ include unordered_map
-- Looking for C++ include unordered_map - not found
-- Looking for C++ include tr1/unordered_map
-- Looking for C++ include tr1/unordered_map - found
-- Found tr1/unordered_map/set in std::tr1 namespace.
-- Looking for C++ include memory
-- Looking for C++ include memory - found
-- Performing Test HAVE_SHARED_PTR_IN_STD_NAMESPACE
-- Performing Test HAVE_SHARED_PTR_IN_STD_NAMESPACE - Failed
-- Performing Test HAVE_SHARED_PTR_IN_TR1_NAMESPACE
-- Performing Test HAVE_SHARED_PTR_IN_TR1_NAMESPACE - Failed
-- Looking for C++ include tr1/memory
-- Looking for C++ include tr1/memory - found
-- Performing Test HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER
-- Performing Test HAVE_SHARED_PTR_IN_TR1_NAMESPACE_FROM_TR1_MEMORY_HEADER - Success
-- Found shared_ptr in std::tr1 namespace using  header.
-- Building Ceres as a static library.

后来分析发现,比较坑爹的是 carto中的库,无论是abls还是glog都是使用它自己稍微有点改动的,并不是普通的那种,找了一下午加一晚上终于发现了问题

到~/cartographer/install_isolated/lib/cartographer_ros文件夹下,使用ldd命令查看ros节点对应的链接库

 ldd cartographer_node |grep glog

得到输出(这个是修改好的正确的,之前报错的时候,库链接到的是usr/local里面自己下载的部分)

libglog.so.0 => /usr/lib/x86_64-linux-gnu/libglog.so.0 (0x00007f38d53a2000)

 可以修改cmakelist改变库的链接 或者将原本多安装的其他版本的glog库卸载

卸载的方法可以底下的参考博客,要根据你的安装方法来卸载

1、使用sudo apt-get install libgoogle-glog-dev安装则可以直接使用sudo apt-get remove libgoogle-glog-dev来卸载,比较方便

2、如果像我一样使用的是源码安装的话,则可以先通过

locate glog

来确定安装位置,一般是在

~$ locate glog
/usr/local/include/glog
/usr/local/include/glog/config.h
/usr/local/include/glog/log_severity.h
/usr/local/include/glog/logging.h
/usr/local/include/glog/raw_logging.h
/usr/local/include/glog/stl_logging.h
/usr/local/include/glog/vlog_is_on.h
/usr/local/lib/libglog.a
/usr/local/lib/cmake/glog

接着执行

sudo rm -rf /usr/local/include/glog/
sudo rm -rf /usr/local/lib/libglog*

就成功把glog卸载了

之后再将这三个文件夹删除再重新编译一般carto即可

Cartographer编译方法及编译出错(glog库链接错误)解决方法_第1张图片 Caption

 

 

参考

https://answers.ros.org/question/300549/failed-to-install-google-cartographer/

https://blog.csdn.net/guangyacyb/article/details/85165231

https://blog.csdn.net/u012348774/article/details/80620685

你可能感兴趣的:(Cartographer编译方法及编译出错(glog库链接错误)解决方法)