gazebo报错:usr/include/gazebo-11/gazebo/msgs/wrench_stamped.pb.h:13:2: error: #error incompatible with

1、错误展示:

编译工作空间时报了这个错误:

usr/include/gazebo-11/gazebo/msgs/wrench_stamped.pb.h:13:2: error: #error incompatible with your Protocol Buffer headers. Please update
   13 | #error incompatible with your Protocol Buffer headers.  Please update

2、原因

Gazebo 11 的代码生成依赖特定版本的 Protobuf(如 3.6.1+),但系统中可能安装了旧版本(如 3.4.0)或存在多个版本冲突。例如:

  • 头文件 wrench_stamped.pb.h 在生成时要求最低 Protobuf 版本为 3.6.1(通过 GOOGLE_PROTOBUF_VERSION 宏判断),而当前系统 Protobuf 库版本低于此值。
  • 若通过源码安装 Protobuf 后未正确配置环境,可能导致编译时链接到旧版本。

3、解决方案:

检查 Gazebo 头文件中的 Protobuf 版本限制。例如,打开 /usr/include/gazebo-11/gazebo/msgs/wrench_stamped.pb.h,查找类似以下代码:

#if GOOGLE_PROTOBUF_VERSION < 3006001
#error This file was generated by a newer version of protoc which is
#error incompatible with your Protocol Buffer headers.  Please update
#error your headers.
#endif
#if 3006001 < GOOGLE_PROTOBUF_MIN_PROTOC_VERSION
#error This file was generated by an older version of protoc which is
#error incompatible with your Protocol Buffer headers.  Please
#error regenerate this file with a newer version of protoc.
#endif

这里的注释信息:

#if GOOGLE_PROTOBUF_VERSION < 3006001

说明的就是Protobuf版本必须大于等于3.6.1,所以这里只需要重新安装Protobuf 3.6.1即可。

1)首先卸载旧版本,在终端执行以下命令:

# 移除 apt 安装的版本
sudo apt remove libprotobuf-dev protobuf-compiler

# 删除源码安装的版本(假设安装在 /usr/local/)
sudo rm -rf /usr/local/lib/libprotobuf* /usr/local/include/google/protobuf

2)根据 Gazebo 需求安装指定版本(以 3.6.1 为例):

# 下载源码
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protobuf-cpp-3.6.1.tar.gz
tar -xzf protobuf-cpp-3.6.1.tar.gz
cd protobuf-3.6.1

# 编译安装
./autogen.sh
./configure --prefix=/usr/local
make -j$(nproc)
sudo make install

# 更新动态链接库
sudo ldconfig

3)验证安装

protoc --version  # 应输出 libprotoc 3.6.1

这样重新编译工程应该就不会报这个错误了。

你可能感兴趣的:(服务器,运维)