1. 查看生成.pb文件的protoc版本(编译环境)
protoc --version
2. 比如原始编译版本是3.19.1,在官网下载对应版本
3. 按照如下命令安装
cd protobuf-xxx
./autogen.sh
./configure
make // 耗时较长
make check // 非必须
sudo make install
sudo ldconfig
xxx.pb.h: #error this file was generated by an older version of protoc …
#error incompatible with your Protocol Buffer headers.
#error please regenerate this file with a newer version of protoc
解决办法
卸载protoc重新安装指定版本,指定版本下载安装上面介绍过了
protobuf的卸载
sudo apt-get remove libprotobuf-dev
which protoc // 查看可执行文件路径
sudo rm /usr/local/bin/protoc // 删执行文件
//(也可能是/usr/bin/protoc)
sudo rm -rf /usr/local/include/google //头文件
sudo rm -rf /usr/local/lib/libproto* //库文件
protoc: error while loading shared libraries: libprotoc.so.23: cannot open shared object file: no such file or directory
参考文章:
protobuf安装命令
ubuntu18.04安装最新版本protobuf
protobuf卸载1
protofbuf卸载2
created by shuaixio, 2021.11.24