Protobuf2.6集成到ios平台
最近我们项目组把socket通信的数据格式使用google 的Protobuf,简称“PB”,具体protobuf跟Json Xml相比有哪些优点,你们去度娘吧。
接下来我给大家讲下怎么集成到ios项目中吧,小编也走了一段弯路,希望这篇文章能帮助您少走弯路,少一分套路,多一份真诚。
首先进入下面这个链接,如果您之前看过其他帖子,他让你去github上面去下载,那么我可以告诉您,那种方法坑比较多。因为还需要使用automake autoconf来配置。。
*1.1建议大家去官网去下载
https://developers.google.com/protocol-buffers/


*1.2下载后解压

说明:如果你是去官网下载的,应该会跟上图的文件一样,就应该是这样的,后面你执行才不会报错。
*1.3编译
*1.3.1: cd 到你压缩后的路径下
例如:cd /Users/jianxing/Downloads/protobuf-2.6.1
*1.3.2:运行 ./configure
*1.3.3:运行 make
*1.3.4: 运行 make check
*1.3.5: 运行 make install
如果出现permission deny,请在前面加sudo赋予权限。
一般情况下,你应该是最高权限,admin
说明:如果你解压后的文件没错的话,这4步是终端命令在那跑啊跑,看起来很高端的样子,实际上,我一句都看不懂.
到这里其实已经把插件安装成功了!
打开/usr/local/bin,可以看到proton

打开/usr/local/include 可以看到google

打开/usr/local/lib 找到libprotobuf.a

*3集成到你的项目中就可以了,建议你把libprotobuf.a这个静态库放在你的工程目录下
这一部分,我相信大多数人都可以完成,就快速的过吧
*3.1 添加第三方库


*3.2 searchPath


*3.4这一部分放在底部有点可惜了,但是必须按步骤走,
1: 打开终端: cd 到放proto的文件夹下
2:输入命令:protoc --plugin=/usr/local/bin/protoc addressbook.proto --cpp_out="./" 这个是生成c++ .h .cc文件
3:输入命令:protoc --plugin=/usr/local/bin/protoc addressbook.proto --objc_out="./" 这个是生成oc .h .m 文件
我是拿 examples里面的photo来演示的,所以大家参考一下,这部分生成有问题可以在下方评论,楼主愿意与你一起研究,一起探讨。

另外还有一种傻瓜式的安装方式,它是下载一个sh脚本,直接丢到终端里面去就可以了
友情推荐大家阅读
http://blog.csdn.net/qq446569365/article/details/44957971