Qt使用protobuf笔记

idwtwt 2019-09-28

解决使用protobuf库过程中出现的编译问题。protobuf和XML,json一样的数据结构。

问题1

  • 缺protobuf库,可以定义PROTOBUF_USE_DLLS来链接protobuf库。
无法解析的外部符号 "class google::protobuf::internal::ExplicitlyConstructed<class std::basic_string<char,struct std::char_traits,class std::allocator > >
  • 解决方法:
DEFINES += PROTOBUF_USE_DLLS

问题2

  • std::min,std::max与windows.h的min,max冲突了。
.pb.h:189: warning: C4003: 类函数宏的调用“min”参数不足
.pb.h:189: warning: C4003: 类函数宏的调用“max”参数不足
.pb.h:189: error: C2589: “(”:“::”右边的非法标记
UserInfo_STATE_UserInfo_STATE_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits<::google::protobuf::int32>::min(),
UserInfo_STATE_UserInfo_STATE_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits<::google::protobuf::int32>::max()
  • 解决方法:

屏蔽windows.h的min, max方法

DEFINES += NOMINMAX

相关推荐