1、查看当前protoc版本:protoc --version
# protoc --version
libprotoc 3.19.4
2、查看proto生成的.h文件的编译器版本
#if GOOGLE_PROTOBUF_VERSION < 3001000
#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 3001000 < 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
3、查看系统包含的protobuf库文件:ldconfig -p | grep libprotobuf.so
# ldconfig -p | grep libprotobuf.so
libprotobuf.so.30 (libc6,x86-64) => /usr/local/lib/libprotobuf.so.30
libprotobuf.so.11 (libc6,x86-64) => /root/miniconda3/envs/d2l/lib/python3.7/site-packages/tushare/subs/ht_subs/com/libs/linux/libprotobuf.so.11
libprotobuf.so (libc6,x86-64) => /usr/local/lib/libprotobuf.so
步骤一二即能确认版本是否兼容,不兼容需要卸载现有protoc,安装生成现有.h 版本的protoc
卸载源码手动安装的 protobuf
# make uninstall
Making uninstall in .
make[1]: Entering directory `/root/app/protobuf-3.19.4'
( cd '/usr/local/lib/pkgconfig' && rm -f protobuf.pc protobuf-lite.pc )
make[1]: Leaving directory `/root/app/protobuf-3.19.4'
Making uninstall in src
make[1]: Entering directory `/root/app/protobuf-3.19.4/src'
安装新版本protobuf
$ cd protobuf-3.1.0/
$ ./configure
$ make
$ make check
$ sudo make install
$ sudo ldconfig # refresh shared library cache.