在GOOGLE_PROTOBUF_MIN_PROTOC_VERSION检查期间编译时出现协议缓冲区错误

the*_*qbf 10 c++ protocol-buffers protoc

我目前收到一个错误,指出我在protoc生成的头文件中的这些行:

#if 2006001 < 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
Run Code Online (Sandbox Code Playgroud)

但我的protoc版本与上面的版本匹配:

protoc --version
libprotoc 2.6.1
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

最初我的protoc版本是3.0.0然后通过同步回到2.6.1并执行步骤重新安装它; make distclean,./ configure,make,make install来安装所需的2.6.1版本.我需要旧版本,因为那是我们服务器中安装的版本.

Ken*_*rda 11

问题是系统上安装的标头(在/ usr/include/google/protobuf或/ usr/local/include/google/protobuf中)来自较新版本的Protocol Buffers而不是你的protoc.可能是您在不同位置安装了两个版本,并且正在使用错误的版本.

但我的protoc版本与上面的版本匹配:

是的,因为该代码是由您生成的protoc,并且它知道自己的版本.该代码询问:"我的版本(2006001)是否低于所需安装的标头声称的最低版本(GOOGLE_PROTOBUF_MIN_PROTOC_VERSION)?"

  • @the_qbf:是的,看看`google/protobuf/stubs/common.h`并查找大约100行的`GOOGLE_PROTOBUF_VERSION`宏. (6认同)
  • 有没有办法检查我的系统中安装了哪个版本的标头?我尝试查看文件本身,但找不到任何关于它是什么版本的提示。 (2认同)