下载
看到论坛很多ios的配置方式.这里讲一种最简单的.直接去Google 官方下载最新的已经编译好的安装就行了.
先看官方文档:
The protocol compiler is written in C++. If you are using C++, please follow
the C++ Installation Instructions to install protoc along
with the C++ runtime.
For non-C++ users, the simplest way to install the protocol compiler is to
download a pre-built binary from our release page:
https://github.com/google/protobuf/releases
直接在https://github.com/google/protobuf/releases 找到已经编译好的objectivec版本下载就行了.或者到csdn里面下载一份
http://download.csdn.net/detail/mtc1256/9600566
下载好之后开始安装
cd protobuf-3.0.0
./configure
make -j8
sudo make install
验证是否安装成功
$ which protoc
/usr/local/bin/protoc
写一个测试脚本生成proto代码
message.proto
syntax = "proto3";
package msg;
message TestData
{
bool objid = 1;
bool objnum = 2;
}
通过Makefile 脚本来调用protoc
Makefile
#$Id$
BUILD_DIR_ROOT = $(PWD)
PROTO_OUT_DIR = $(BUILD_DIR_ROOT)/protoOut
proto:
@protoc -I=$(BUILD_DIR_ROOT) --objc_out=$(PROTO_OUT_DIR) $(BUILD_DIR_ROOT)/message.proto
生成proto 文件
$ make proto
这样就会生成.h .m 了剩下的就是根据官方文档嵌入到oc工程,使用就好了生成目录是这样的