configure.ac:30: error: possibly undefined macro: AC_PROG_LIBTOOL If this token and others are legitimate, please use m4_pattern_allow. See the Autoconf documentation. autoreconf: /usr/local/Cellar/autoconf/2.69/bin/autoconf failed with exit status: 1
接下来要在自己的项目中加入protobuf的库文件,这里推荐使用cocoapod来添加,在podfile文件中添加 pod ‘Protobuf’, ‘~> 3.3.0’ 。当然你也可以直接把protobuf拖进自己的项目中使用。cocoapod的使用,相信大家都会,不会的话可以找google
proto的生成与使用
首先要创建.proto文件,文件名自起。后缀要用.proto,比如这里使用的 UserModel.proto。 syntax = “proto3”,指定使用的proto版本,没有会报以下错误: No syntax specified for the proto file: UserModel.proto. Please use ‘syntax = “proto2”;’ or ‘syntax = “proto3”;’ to specify a syntax version. (Defaulted to proto2 syntax.)
UserModel.proto:5:15: Explicit 'optional' labels are disallowed in the Proto3 syntax. To define 'optional' fields in Proto3, simply remove the 'optional' label, as fields are 'optional' by default.
protoc arc forbids object-c object in struct //引用官方文档的说明 //Add objectivec/\*.h & objectivec/\*.m except for objectivec/GPBProtocolBuffers.m to your project. //If the target is using ARC, remember to turn off ARC (-fno-objc-arc) for the .m files. //The files generated by protoc for the *.proto files (\*.pbobjc.h and \*.pbobjc.m) are then also added to the target.
// Generated by the protocol buffer compiler. DO NOT EDIT! // source: UserModel.proto
// This CPP symbol can be defined to use imports that match up to the framework // imports needed when using CocoaPods. #if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 #endif
#if GOOGLE_PROTOBUF_OBJC_VERSION < 30002 #error This file was generated by a newer version of protoc which is incompatible with your Protocol Buffer library sources. #endif #if 30002 < GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION #error This file was generated by an older version of protoc which is incompatible with your Protocol Buffer library sources. #endif
/** * Exposes the extension registry for this file. * * The base class provides: * @code * + (GPBExtensionRegistry *)extensionRegistry; * @endcode * which is a @c GPBExtensionRegistry that includes all the extensions defined by * this file and all files that it depends on. **/ @interfaceUserModelRoot : GPBRootObject @end
// Generated by the protocol buffer compiler. DO NOT EDIT! // source: UserModel.proto
// This CPP symbol can be defined to use imports that match up to the framework // imports needed when using CocoaPods. #if !defined(GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS) #define GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS 0 #endif
// No extensions in the file and no imports, so no need to generate // +extensionRegistry.
@end
#pragma mark - UserModelRoot_FileDescriptor
static GPBFileDescriptor *UserModelRoot_FileDescriptor(void) { // This is called by +initialize so there is no need to worry // about thread safety of the singleton. static GPBFileDescriptor *descriptor = NULL; if (!descriptor) { GPB_DEBUG_CHECK_RUNTIME_VERSIONS(); descriptor = [[GPBFileDescriptor alloc] initWithPackage:@"first_pro" syntax:GPBFileSyntaxProto3]; } return descriptor; }