Qt使用protobuf筆記

  • 2019 年 10 月 11 日
  • 筆記

解決使用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