Ubuntu18.04上cartographer 和PX4 gazebo仿真对Google protoc或者说Protocol Buffers依赖问题

Ubuntu18.04上cartographer 和PX4 gazebo仿真对Google protoc或者说Protocol Buffers依赖问题

参考连接:
https://google-cartographer-ros.readthedocs.io/en/latest/compilation.html
https://github.com/protocolbuffers/protobuf/blob/master/src/README.md
https://blog.csdn.net/weixin_40599145/article/details/89061073

先搭建PX4开发平台,在Firmware文件夹打开终端运行make px4_sitl gazebo命令,代码编译成功且可以打开gazebo进行仿真。
由于项目需要用到cartographer,因此在PX4开发平台已经搭好的情况下按照cartographer官方文档安装cartographer,cartographer安装好且可以用了,在Firmware文件夹下打开终端运行make disclean命令清除编译项,运行命令make px4_sitl gazebo从新编译,会出现大量类似下面的错误:

/home/qjny/local_install/google/protocbuff/include/google/protobuf/arenastring.h:225:31: note:   candidate expects 0 arguments, 1 provided
In file included from /usr/include/gazebo-9/gazebo/msgs/MessageTypes.hh:132:0,
                 from /usr/include/gazebo-9/gazebo/msgs/msgs.hh:35,
                 from /usr/include/gazebo-9/gazebo/sensors/Sensor.hh:33,
                 from /usr/include/gazebo-9/gazebo/sensors/CameraSensor.hh:24,
                 from /home/qjny/PX4_Files/Firmware/Tools/sitl_gazebo/include/gazebo_geotagged_images_plugin.h:23,
                 from /home/qjny/PX4_Files/Firmware/Tools/sitl_gazebo/src/gazebo_geotagged_images_plugin.cpp:18:
/usr/include/gazebo-9/gazebo/msgs/world_modify.pb.h: In member function ‘const string& gazebo::msgs::WorldModify::cloned_uri() const’:
/usr/include/gazebo-9/gazebo/msgs/world_modify.pb.h:339:93: error: no matching function for call to ‘google::protobuf::internal::ArenaStringPtr::GetNoArena(const string*) const’
   return cloned_uri_.GetNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited());
                                                                                             ^
In file included from /usr/include/ignition/msgs1/ignition/msgs/altimeter.pb.h:23:0,
                 from /usr/include/ignition/msgs1/ignition/msgs/MessageTypes.hh:31,
                 from /usr/include/ignition/msgs1/ignition/msgs/Utility.hh:29,
                 from /usr/include/ignition/msgs1/ignition/msgs.hh:25,
                 from /usr/include/ignition/transport4/ignition/transport/Node.hh:32,
                 from /usr/include/gazebo-9/gazebo/sensors/CameraSensor.hh:22,
                 from /home/qjny/PX4_Files/Firmware/Tools/sitl_gazebo/include/gazebo_geotagged_images_plugin.h:23,
                 from /home/qjny/PX4_Files/Firmware/Tools/sitl_gazebo/src/gazebo_geotagged_images_plugin.cpp:18:
/home/qjny/local_install/google/protocbuff/include/google/protobuf/arenastring.h:225:31: note: candidate: const string& google::protobuf::internal::ArenaStringPtr::GetNoArena() const
   inline const ::std::string& GetNoArena() const { return *ptr_; }
                               ^~~~~~~~~~
/home/qjny/local_install/google/protocbuff/include/google/protobuf/arenastring.h:225:31: note:   candidate expects 0 arguments, 1 provided
At global scope:
cc1plus: warning: unrecognized command line option ‘-Wno-address-of-packed-member’
ninja: build stopped: subcommand failed.
[739/743] Linking CXX executable bin/px4
FAILED: external/Stamp/sitl_gazebo/sitl_gazebo-build 
cd /home/qjny/PX4_Files/Firmware/build/px4_sitl_default/build_gazebo && /usr/bin/cmake --build .
ninja: build stopped: subcommand failed.
Makefile:205: recipe for target 'px4_sitl' failed
make: *** [px4_sitl] Error 1

这是因为Ubuntu18.04默认安装的是libprotoc 3.0.0,且PX4的gazebo仿真编译也依赖于libprotoc 3.0.0。但是cartographer依赖于libprotoc 3.4.0,按照cartographer官方文档安装cartographercartographer的话,就会删除libprotoc 3.0.0,重新安装libprotoc 3.4.0,导致PX4的gazebo仿真依赖项出现问题,运行make px4_sitl gazebo就会出现大量上述错误,解决办法如下:

##### 1. 首先在按照cartographer官方文档安装cartographer的时候,不要执行命令src/cartographer/scripts/install_proto3.sh
##### 2. git protobuf源码
git clone https://github.com/google/protobuf.git
cd protobuf
##### 3. 修改protobuf版本为v3.4.1,安装时会自动安装3.4.0
git checkout tags/v3.4.1
git checkout -b v3.4.1
./autogen.sh
##### 4. 修改安装路径
./configure --prefix=/home/yours/local_install/google/protocbuff/ #yours是你对你计算机取的名字
##### 5. 编译protobuf源码
make -j8
##### 6.安装protobuf3.4.0
make install

这样你就在你的Ubuntu18.04里安装了两个protoc,一个是libprotoc 3.0.0,用于PX4,一个是libprotoc 3.4.0,用于cartographer。
同时,你还需要在你的.bashrc文件末尾添加如下内容

####编译PX4时,将如下内容注释掉,编译cartographer时,将如下内容打开
####### add protobuf lib path ########/home/qjny/local_install/lib
export PATH=/home/qjny/local_install/google/protocbuff/bin/:$PATH
#(动态库搜索路径) 程序加载运行期间查找动态链接库时指定除了系统默认路径之外的其他路径
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/qjny/local_install/google/protocbuff/lib/
#(静态库搜索路径) 程序编译期间查找动态链接库时指定查找共享库的路径
export LIBRARY_PATH=$LIBRARY_PATH:/home/qjny/local_install/google/protocbuff/lib/
#执行程序搜索路径
export PATH=$PATH:/home/qjny/local_install/google/protocbuff/bin/
#c程序头文件搜索路径
export C_INCLUDE_PATH=$C_INCLUDE_PATH:/home/qjny/local_install/google/protocbuff/include/
#c++程序头文件搜索路径
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/home/qjny/local_install/google/protocbuff/include/
#pkg-config 路径
export PKG_CONFIG_PATH=/home/qjny/local_install/google/protocbuff/lib/pkgconfig/
######################################

同时在cartographer程序包的CMakeLists.txt文件开头添加如下内容:

###################################################
INCLUDE_DIRECTORIES(/home/qjny/local_install/google/protocbuff/include/)
LINK_DIRECTORIES(/home/qjny/local_install/google/protocbuff/lib/)
###################################################

添加位置如下:
在这里插入图片描述将.bashrc文件里之前添加的内容注释掉时,查看protoc版本及安装路径:
在这里插入图片描述
protoc版本及安装路径编译PX4成功:
在这里插入图片描述在这里插入图片描述将.bashrc文件里之前添加的内容打开时,查看protoc版本及安装路径:

在这里插入图片描述在这里插入图片描述在这里插入图片描述cartographer安装成功
在这里插入图片描述

注:
可以在cartographer工作空间创建一个 .sh文件,将这部分内容添加到 .sh文件里面去,当要对cartographer工作空间进行编译时,先source一下这个 .sh文件就可以了,我这里将如下内容添加到了 dependent_ervironment.sh文件里面,每次source一下再编译就不会报错:

####编译PX4时,将如下内容注释掉,编译cartographer时,将如下内容打开
####### add protobuf lib path ########/home/qjny/local_install/lib
export PATH=/home/qjny/local_install/google/protocbuff/bin/:$PATH
#(动态库搜索路径) 程序加载运行期间查找动态链接库时指定除了系统默认路径之外的其他路径
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/qjny/local_install/google/protocbuff/lib/
#(静态库搜索路径) 程序编译期间查找动态链接库时指定查找共享库的路径
export LIBRARY_PATH=$LIBRARY_PATH:/home/qjny/local_install/google/protocbuff/lib/
#执行程序搜索路径
export PATH=$PATH:/home/qjny/local_install/google/protocbuff/bin/
#c程序头文件搜索路径
export C_INCLUDE_PATH=$C_INCLUDE_PATH:/home/qjny/local_install/google/protocbuff/include/
#c++程序头文件搜索路径
export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/home/qjny/local_install/google/protocbuff/include/
#pkg-config 路径
export PKG_CONFIG_PATH=/home/qjny/local_install/google/protocbuff/lib/pkgconfig/
######################################

在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值