安装cartographer遇到的问题

本文详细介绍了在安装Cartographer过程中遇到的protobuf makecheck失败问题及其解决方案。主要问题为‘dynamic_init_dummy_google_2fprotobuf_2fany_5ftest_2eproto’被定义但未使用,通过修改Makefile.in文件中的编译选项成功解决了该问题。

安装cartographer遇到的问题的中大部分的问题在在百度上都能找到问题的答案,但是有过一个问题我bug了很久

在安装protobuf的时候make check直接失败了,得到的信息是

‘dynamic_init_dummy_google_2fprotobuf_2fany_5ftest_2eproto’ defined but not used [-Werror=unused-variable]

最后得到的解决办法是google上找到的
1、打开protobuf的文件夹,找到src文件夹下的Makefile.in文件,打开
去掉

no_warning_test_CXXFLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_DEF) $(ZLIB_DEF) \
                           -Wall -Wextra -Wno-unused-parameter -Og

大概在2044下面。
如此继续就可通过了

$ ./configure
$ make
$ make check
$ sudo make install
$ sudo ldconfig # refresh shared library cache.

最后make check通过的样子应该是这样的额
在这里插入图片描述

<think>我们正在处理一个关于在ROS1中安装Cartographer问题。根据之前的对话历史,用户遇到了因为工作区中存在非Catkin而导致的构建错误,并已建议使用`catkin_make_isolated`。现在用户想要安装Cartographer,这是一个常用的SLAM算法,在ROS中通常以ROS的形式提供。根据引用[1][2],安装Cartographer需要一些特定的步骤,安装依赖、安装Protobuf3(需要先卸载ROS自带的Protobuf2)、安装CeresSolver、安装Cartographer及其依赖Abseil,最后编译cartographer_ros。同时,引用[2]提到在安装过程中可能需要注释掉cartographer中package.xml的libabsl-dev依赖,并卸载abseil库(因为Cartographer自带abseil,如果系统安装了可能会冲突)。因此,我们需要为用户提供一个详细的安装指南,括以下步骤:1.安装ROS(如果尚未安装)2.安装依赖3.安装Protobuf3.6.0(需要先卸载Protobuf2)4.创建并配置ROS工作空间5.安装CeresSolver6.安装Cartographer和Abseil7.编译cartographer_ros同时,我们还需要注意在安装过程中可能遇到的坑,比如Protobuf版本冲突、Abseil库冲突等。由于在之前的问题中,用户的工作区可能含非Catkin,因此我们在编译cartographer_ros时应该使用`catkin_make_isolated`,以避免出现类似问题。接下来,我们将按照这些步骤详细说明。注意:本指南假设用户使用的是Ubuntu20.04和ROSNoetic(因为引用[2]提到了这个组合)。如果用户使用的是其他版本,可能需要调整。###步骤1:安装ROSNoetic如果尚未安装ROS,请按照官方指南安装ROSNoetic。```bashsudosh-c'echo"debhttp://packages.ros.org/ros/ubuntu$(lsb_release-sc)main">/etc/apt/sources.list.d/ros-latest.list'sudoaptinstallcurlcurl-shttps://raw.githubusercontent.com/ros/rosdistro/master/ros.asc|sudoapt-keyadd-sudoaptupdatesudoaptinstallros-noetic-desktop-fullecho"source/opt/ros/noetic/setup.bash">>~/.bashrcsource~/.bashrc```###步骤2:安装依赖安装构建Cartographer所需的依赖:```bashsudoaptupdatesudoaptinstall-ypython3-wstoolpython3-rosdepninja-buildstow```###步骤3:安装Protobuf3.6.0Cartographer需要Protobuf3.0.0或更高版本,而ROSNoetic自带的Protobuf版本可能过低,因此需要先卸载ROS的Protobuf2并安装Protobuf3.6.0。####3.1卸载ROS自带的Protobuf2```bashsudoapt-getremovelibprotobuf-devwhichprotoc#通常输出为/usr/bin/protoc,如果存在则删除sudorm/usr/bin/protoc```####3.2安装Protobuf3.6.0```bash#克隆Protobuf源码gitclone-bv3.6.0https://github.com/protocolbuffers/protobuf.gitcdprotobufgitsubmoduleupdate--init--recursive#编译安装./autogen.sh./configuremake-j$(nproc)makecheck-j$(nproc)sudomakeinstallsudoldconfig#检查protoc版本protoc--version#应该显示3.6.0```###步骤4:创建并配置ROS工作空间创建一个新的工作空间,专门用于安装Cartographer,以避免与现有工作区冲突。```bashmkdir-p~/cartographer_ws/srccd~/cartographer_wswstoolinitsrc```###步骤5:安装CeresSolverCeresSolver是一个非线性优化库,Cartographer需要它。```bashsudoapt-getinstall-ylibgoogle-glog-devlibgflags-devsudoapt-getinstall-ylibatlas-base-devsudoapt-getinstall-ylibsuitesparse-dev#从源码安装(推荐1.13.0或更高版本)gitclonehttps://github.com/ceres-solver/ceres-solver.gitcdceres-solvergitcheckout1.13.0#或者选择更新的稳定版本mkdirbuildcdbuildcmake..make-j$(nproc)sudomakeinstall```###步骤6:安装Cartographer和AbseilCartographer自带了Abseil,所以不需要单独安装系统的libabsl-dev,否则会引起冲突。因此,如果系统安装了abseil,需要先卸载(引用[2]中提到了这一点)。####6.1卸载系统abseil库(如果已安装)```bashsudoapt-getremovelibabsl-dev```####6.2克隆Cartographercartographer_ros源码```bashcd~/cartographer_ws/srcgitclonehttps://github.com/cartographer-project/cartographer.gitgitclonehttps://github.com/cartographer-project/cartographer_ros.git```####6.3使用wstool安装其余依赖```bashwstoolupdate-tsrc```####6.4修改package.xml(避免依赖冲突)根据引用[2],需要注释掉cartographer中package.xml的libabsl-dev依赖,因为Cartographer自带abseil。打开文件:`~/cartographer_ws/src/cartographer/package.xml`找到行:`<depend>libabsl-dev</depend>`(可能在第46行)并注释掉,改为:```xml<!--<depend>libabsl-dev</depend>-->```####6.5安装依赖```bashcd~/cartographer_wsrosdepupdaterosdepinstall--from-pathssrc--ignore-src--rosdistro=noetic-y```###步骤7:编译cartographer_ros由于Cartographer可能含非Catkin(实际上是Catkin,但为了兼容性和避免之前的问题),我们使用`catkin_make_isolated`进行编译。```bashcd~/cartographer_wscatkin_make_isolated--install--use-ninja```编译完成后,记得source安装空间:```bashsource~/cartographer_ws/install_isolated/setup.bash```###测试安装现在可以测试安装是否成功。下载一个测试用的bag文件,然后运行Cartographer的demo。```bash#下载2D测试数据(较大,约470MB)wget-P~/Downloadshttps://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag#运行2Ddemoroslaunchcartographer_rosdemo_backpack_2d.launchbag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag```如果一切正常,应该能看到RViz界面并开始建图。###常见问题解决1.**Protobuf版本冲突**:确保`protoc--version`输出3.6.0,并且ROS的Protobuf已被卸载。2.**Abseil冲突**:确保卸载了系统的libabsl-dev,并注释了cartographer中package.xml的相关依赖。3.**编译错误**:如果编译过程中出现错误,请检查依赖是否全部安装,尤其是CeresSolver和Protobuf的安装。希望这个指南能帮助您成功安装Cartographer。如果遇到其他问题,请参考Cartographer的官方文档。[^1]:[Ubuntu18.0420.04在ROS1下安装CartographerCartographer_ROS【方法与避坑~】](参考链接1)[^2]:[Ubuntu20.04安装ROS1(noetic)+cartographer](参考链接2)[^3]:[ROS进阶学习(六)--谷歌Cartographer安装测试1](参考链接3)§§相关问题§§1.如何更新Protobuf到更高版本(如3.8.0)?2.如何将Cartographer集成到已有的ROS导航堆栈?3.如何调整Cartographer的参数以获得更好的建图效果?</think> 以下是在 ROS 1(特别是 Noetic 版本)上安装 Cartographer SLAM 系统的完整指南,基于最佳实践和常见避坑方案: ### 🛠️ ROS 1 安装 Cartographer 完整步骤 #### 1️⃣ 安装 ROS Noetic (如果未安装) ```bash # 设置软件源 sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list' sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 sudo apt update # 安装完整版ROS sudo apt install ros-noetic-desktop-full echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc source ~/.bashrc ``` #### 2️⃣ 安装系统依赖 ```bash sudo apt install -y python3-wstool python3-rosdep ninja-build stow ``` #### 3️⃣ 安装 Protobuf 3 (关键步骤⚠️) ```bash # 卸载ROS自带的Protobuf 2 sudo apt-get remove libprotobuf-dev sudo rm /usr/bin/protoc # 安装Protobuf 3.6.0 git clone -b v3.6.0 https://github.com/protocolbuffers/protobuf.git cd protobuf git submodule update --init --recursive ./autogen.sh ./configure make -j$(nproc) make check sudo make install sudo ldconfig protoc --version # 应显示 libprotoc 3.6.0 ``` #### 4️⃣ 创建工作空间 ```bash mkdir -p ~/cartographer_ws/src cd ~/cartographer_ws wstool init src ``` #### 5️⃣ 安装 Ceres Solver (1.13.0+) ```bash sudo apt-get install -y libgoogle-glog-dev libgflags-dev sudo apt-get install -y libatlas-base-dev sudo apt-get install -y libsuitesparse-dev git clone https://github.com/ceres-solver/ceres-solver.git cd ceres-solver git checkout 1.14.0 # 选择稳定版本 mkdir build cd build cmake .. -DBUILD_TESTING=OFF make -j$(nproc) sudo make install ``` #### 6️⃣ 安装 Cartographer & Abseil ```bash cd ~/cartographer_ws/src git clone https://github.com/cartographer-project/cartographer.git git clone https://github.com/cartographer-project/cartographer_ros.git # 关键修改:解决abseil冲突[^2] sed -i 's/<depend>libabsl-dev<\/depend>/<!-- & -->/' cartographer/package.xml # 安装依赖 rosdep update rosdep install --from-paths src --ignore-src --rosdistro=noetic -y ``` #### 7️⃣ 编译安装(使用隔离编译) ```bash cd ~/cartographer_ws catkin_make_isolated --install --use-ninja source install_isolated/setup.bash # 重要!每次使用前需source ``` #### 8️⃣ 验证安装 ```bash # 下载测试数据集[^3] wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag # 运行测试 roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag ``` ### ⚠️ 常见问题解决方案 1. **Protobuf 版本冲突** 确保彻底卸载旧版:`sudo apt purge libprotobuf-dev protobuf-compiler` 2. **Abseil 库冲突** 除了注释依赖,还需检查系统是否安装abseil: ```bash sudo apt remove libabsl-dev ``` 3. **编译错误 "non-homogeneous workspace"** 必须使用 `catkin_make_isolated` 而非 `catkin_make`[^1] 4. **Ceres 安装失败** 添加 `-DBUILD_TESTING=OFF` 跳过测试 5. **RViz 无显示** 检查话题名称:`rosrun rqt_tf_tree rqt_tf_tree` ### ✅ 验证安装成功 ```bash $ roslaunch cartographer_ros offline_backpack_2d.launch bag_filenames:=${HOME}/test.bag ``` 应在 RViz 中看到实时建图效果: ![Cartographer 2D 建图效果](https://raw.githubusercontent.com/cartographer-project/cartographer_ros/master/doc/source/images/cartographer.gif) *图:Cartographer 2D 建图效果 [^3]* --- 📦 **推荐后续配置**: 1. 将以下内容加入 `~/.bashrc`: ```bash source /opt/ros/noetic/setup.bash source ~/cartographer_ws/install_isolated/setup.bash ``` 2. 对于实际应用,需配置传感器参数: ```xml <!-- 在backpack_2d.lua中修改 --> tracking_frame = "base_link", published_frame = "odom", ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值