$ cd compiler
$ ./autogen.sh
$ ./configure
$ make
$ make install (optional)
The compiler is genrated at src/protoc
. 在src目录下生成一个能够将.proto文件生成.m文件的命令行工具protoc.
当然了,安装的过程中遇到了好几个问题
brew install automake
brew install autoconf
并且,可能还会提示缺少libtool 使用命令 brew install libtool 安装
安装完后 ,执行最后make命令时候,还是会遇到 错误 [message.lo] Error 1,需要改动 文件 message.cc
#include <google/protobuf/stubs/stl_util-inl.h>
+ #include <istream> (增加这一行)
使用方式
将一个 .proto文件(名字叫Person.proto),例如如下的
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
required string number = 1;
optional PhoneType type = 2 [default = HOME];
}
repeated PhoneNumber phone = 4;
}
放到 scr目录下,然后,在src同级建立文件夹 build/objc
调用命令
src/protoc --proto_path=src --objc_out=build/objc src/Person.proto 就会生成
Person.pb.h和Person.pb.m文件两个文件了,这两个文件中,包含的就是 对应的oc对象了,