昨天了解到项目要用到protocol buffer,今天晚上看了一下,了解protobuf本质上就是一个信息表达协议+编辑,解析库。

linux开源软件都一个模式,先./configure --help > build.sh 看看有那些东西,再configure make 。。。

根据官网文档弄个简单write,read 的test大致了解一下是啥情况。

ok,到这里我们已经用上protocol buffer了,下面要把它编译到cocos2dx中去。

本质上就是iphone simulator,iOS,android ndk几个版本(win直接有工程,我还没有去试)

这里,网上有现成的教学:http://www.giraffe-games.com/using-protobuf-protocol-buffers-on-iphone-ios/

https://github.com/dinote/protobuf-mobile-build (这个是跨平台编译配置文件,我下面会修正和优化)

原文如下:

by admin
|on March 9, 2013
|in Blog

Protocol buffers are a flexible, efficient, automated mechanism for serializing structured data – think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages. As google puts it: “Protocol buffers are now Google’s lingua franca for data” and if it’s good enough for google, then it must be worth checking out!

We use protocol buffers to serialize persistant data for our IOS and Android games. Creating classes that persist data like shop, high scores, player preferences, achievements can be done in minutes with protobuf. And that why we ♥ protobuf!

This is not a protobuf usage tutorial, for that, you can check out the official documentation: https://developers.google.com/protocol-buffers/docs/overview. What you won’t find in the official documentation is how to make protobuf for iOS, and this is what this tutorial aims to explain. If you need to build protobuf for iOS, then read on 

I’ll show you how to build protobuf library for armv7, armv7s, and i386 architecture, then merge those libraries together into a single fat library that can be used in iOS projects. This library will work on the simulator as well as on the device.

- We used protobuf2.4.1 (the last stable version at the time of writing) https://code.google.com/p/protobuf/downloads/list

- Command line tools can be updated by going to Xcode->Preferences.. then selecting the Downloads tab and selecting Command Line Tools


- to convert protobuf files into source code, you will need a protobuf compiler! You can build and install this compiler by going to protobuf directory and executing the following commands:

$ ./configure

$ make

$ make check

$ make install

To build the ios protobuf static library
copy this script into protobuf directory and name it build-proto-ios.sh, then execute this to give the file execute privilegies:

$ chmod a+x ./build-proto-ios.sh
$ ./build-proto-ios.sh

Go make a cup of coffie, this will take a few minutes  You can also download the precompiled fat ios library from here.

After the compilation is done you will see a new folder under protobuf root called: ios-build. This folder contains libprotobuf-lite.a. This is a static library for iOS.

To import libprotobuf-lite.a into Xcode, just right click on a project directory where you want to import the library, from the drop-down list choose “Add Files to project-name…” and add libprotobuf-lite.a library.

You still need to tell Xcode where to look for protobuf headers. To do this go to your project target build settings and under “Header Search Paths” add the path to protobuf-base-folder/src. The “protobuf-base-folder” being the folder in which you have the protobuf library from google.

option optimize_for = LITE_RUNTIME;
at the start of your proto definition file.

For a tutorial on how to use protobuf, it’s best to check out googles official documentation: https://developers.google.com/protocol-buffers/docs/overview

Happy protobuffing.

If you got any suggestions or question, feel free to ask/suggest!

-------------------文章中提到的shell脚本如下;
configure_for_platform() {
export PLATFORM=$1
#export PLATFORM=iPhoneOS
echo "Platform is ${PLATFORM}" if [ "$PLATFORM" == "iPhoneSimulator" ]; then
export ARCHITECTURE=i386
export ARCH=i686-apple-darwin10
fi if [ "$PLATFORM" == "iPhoneOS" ]; then
export ARCHITECTURE=$2
export ARCH=arm-apple-darwin10
fi export ARCH_PREFIX=$ARCH-
export SDKVER="6.0"
export DEVROOT=/Applications/Xcode.app/Contents/Developer/Platforms/${PLATFORM}.platform/Developer
export SDKROOT="$DEVROOT/SDKs/${PLATFORM}$SDKVER.sdk"
export PKG_CONFIG_PATH="$SDKROOT/usr/lib/pkgconfig:$DEVROOT/usr/lib/pkgconfig"
export AS="$DEVROOT/usr/bin/as"
export ASCPP="$DEVROOT/usr/bin/as"
export AR="$DEVROOT/usr/bin/ar"
export RANLIB="$DEVROOT/usr/bin/ranlib"
#export CPP="$DEVROOT/usr/bin/c++"
#export CXXCPP="$DEVROOT/usr/bin/c++"
export CC="$DEVROOT/usr/bin/gcc"
export CXX="$DEVROOT/usr/bin/g++"
export LD="$DEVROOT/usr/bin/ld"
export STRIP="$DEVROOT/usr/bin/strip"
export LIBRARY_PATH="$SDKROOT/usr/lib" export CPPFLAGS=""
#export CFLAGS="-arch armv7 -fmessage-length=0 -pipe -fpascal-strings -miphoneos-version-min=4.0 -isysroot=$SDKROOT -I$SDKROOT/usr/include -I$SDKROOT/usr/include/c++/4.2.1/"
export CFLAGS="-arch ${ARCHITECTURE} -fmessage-length=0 -pipe -fpascal-strings -miphoneos-version-min=4.0 -isysroot=$SDKROOT -I$SDKROOT/usr/include -I$SDKROOT/usr/include/c++/4.2.1/"
export CXXFLAGS="$CFLAGS"
#export LDFLAGS="-isysroot='$SDKROOT' -L$SDKROOT/usr/lib/system -L$SDKROOT/usr/lib/"
export LDFLAGS="-arch ${ARCHITECTURE} -isysroot='$SDKROOT' -L$SDKROOT/usr/lib/system -L$SDKROOT/usr/lib/" ./configure --host=${ARCH} --with-protoc=protoc --enable-static --disable-shared
} mkdir ios-build #build for iPhoneSimulator
configure_for_platform iPhoneSimulator
make clean
make
cd src;make libprotobuf-lite.la;cd ..
cp src/.libs/libprotobuf-lite.a ios-build/libprotobuf-lite-i386.a #build for iPhoneOS armv7
configure_for_platform iPhoneOS armv7
make clean
make
cd src;make libprotobuf-lite.la;cd ..

cp src/.libs/libprotobuf-lite.a ios-build/libprotobuf-lite-armv7.a#build for iPhoneOS armv7sconfigure_for_platform iPhoneOS armv7smake cleanmake

cd src;make libprotobuf-lite.la;cd ..
cp src/.libs/libprotobuf-lite.a ios-build/libprotobuf-lite-armv7s.amake clean#cerate a fat library containing all achitectures in libprotobuf-lite.axcrun -sdk iphoneos lipo -arch armv7 ios-build/libprotobuf-lite-armv7.a -arch armv7s ios-build/libprotobuf-lite-armv7s.a -arch i386 ios-build/libprotobuf-lite-i386.a -create -output ios-build/libprotobuf-lite.a


脚本中的红色部分是我的改动点。(sorry,发布后才发现,《code》段落中无法引用html标签。反而弄乱脚本了。大家仔细看,能够看明白。
1、我的xcode版本是6.1 ;这个版本号影响到cross编译器地址,如果错误,在你make的时候会提示,很容易修正。
2、我们其实只要编译一个lite库即可,那些compiler,test。。。都和我们无关,所以,直接用make libprotobuf-lite.la来编译那相关的16个文件。出错的几率会小很多很多。(也不用像文章中介绍的那样,先编译安装一个protoc了。)


ok,cross compile over;
1、next we will try how to use this lib in Xcode (cocos2dx)。
2、Android version protobuf
3、to simplify these steps

for the last ,I will upload a cocos2dx project that include iOS/ simulator/ android versions。

TO Be Continue ...

cocos2d-x protobuf; cocos2dx protocol buffer的更多相关文章

  1. protocol buffer

    下载与说明:https://github.com/google/protobuf Google Protocol Buffer 的使用和原理:http://www.ibm.com/developerw ...

  2. Google Protocol Buffer 的使用(一)

    一.什么是Google Protocol Buffer下面是官网给的解释:Protocol buffers are a language-neutral, platform-neutral exten ...

  3. protocol buffer介绍(protobuf)

    一.理论概述0.参考资料入门资料:https://developers.google.com/protocol-buffers/docs/javatutorial更详细的资料:For more det ...

  4. google protocol buffer——protobuf的基本使用和模型分析

    这一系列文章主要是对protocol buffer这种编码格式的使用方式.特点.使用技巧进行说明,并在原生protobuf的基础上进行扩展和优化,使得它能更好地为我们服务. 1.什么是protobuf ...

  5. google protocol buffer——protobuf的使用特性及编码原理

    这一系列文章主要是对protocol buffer这种编码格式的使用方式.特点.使用技巧进行说明,并在原生protobuf的基础上进行扩展和优化,使得它能更好地为我们服务. 在上一篇文章中,我们展示了 ...

  6. google protocol buffer——protobuf的编码原理二

    这一系列文章主要是对protocol buffer这种编码格式的使用方式.特点.使用技巧进行说明,并在原生protobuf的基础上进行扩展和优化,使得它能更好地为我们服务. 在上一篇文章中,我们主要通 ...

  7. google protocol buffer——protobuf的问题及改进一

    这一系列文章主要是对protocol buffer这种编码格式的使用方式.特点.使用技巧进行说明,并在原生protobuf的基础上进行扩展和优化,使得它能更好地为我们服务. 在上一篇文章中,我们完整了 ...

  8. google protocol buffer——protobuf的问题和改进2

    这一系列文章主要是对protocol buffer这种编码格式的使用方式.特点.使用技巧进行说明,并在原生protobuf的基础上进行扩展和优化,使得它能更好地为我们服务. 在上一篇文章中,我们举例了 ...

  9. Protocol Buffer搭建及示例

    本文来源:http://www.tanhao.me/code/150911.html/ Protocol Buffer(简称Protobuf或PB)是由Google推出的一种数据交换格式,与传统的XM ...

随机推荐

  1. 最新HTML BroadcastChannel API引荐

    HTML BroadcastChannel API 当前浏览器中只有Firefox38唯一能支持BroadcastChannel API(在编写本文的时间点),而Firefox38官方宣称要到2015 ...

  2. css3中display和box小结

    display:table用处: 1.创建登高列 2.实现大小不确定元素的垂直居中 3.容器内子项目数目未知,子项目平均分配容器的水平空间 float必须指定其宽度才行,不确定的话就用display: ...

  3. Sqlserver2008安装部署文档

    Sqlserver2008部署文档 注意事项: 如果你要安装的是64位的服务器,并且是新机器.那么请注意,你需要首先需要给64系统安装一个.net framework,如果已经安装此功能,请略过这一步 ...

  4. SqlDataReader的关闭问题

    原文:SqlDataReader的关闭问题 昨天一个朋友使用Repeater绑定数据源时,老是出现"阅读器关闭时尝试调用 FieldCount 无效."错误. 我看了他的代码,使用 ...

  5. IOS开发之——使用SBJson拼接Json字符串

    SBJson包的下载地址在上一篇文章中. 能够使用NSDictionary中的键值对来拼接Json数据,很方便,也能够进行嵌套,直接上代码: //開始拼接Json字符串 NSDictionary *d ...

  6. Mvc 6 中创建 Web Api

    如何在Mvc 6 中创建 Web Api以及如何脱离IIS实现自我托管 微软推出的Asp.net vNext(asp.net 5.0)的其中的一个目标就是统一mvc 和web api 的框架.接下来我 ...

  7. Android高效的应用程序开发工具集1---ant构建一个简单的Android工程

    在java编译那些事通过提到ant编译Java工程,如今扩大到用它来构建Android目,事实上道理是相通的.变化的仅仅是使用的形式.ant构建相比IDE的优点是多个子项目使用自己定义jar包时,an ...

  8. 编译安装gimp插件之Mathmap(流水记录)

    本文为在Fedora 20下编译安装Mathmap1.3.5的编译过程,如果你仅仅需要快速的安装Mathmap,那么请拉至文末的"快速安装" 其实,过程还是很有趣的,充满Error ...

  9. MVC无刷新分页

    MVC无刷新分页(即局部刷新,带搜索,页数选择,排序功能)   我查看了很多网站,大部分评论分页都是局部刷新的,可大部分电商商品展示分页都是有刷新页面的,于是我便做了一个商品展示无刷新分页的例子.接下 ...

  10. 松瀚SN8P2501 定时器初始化程序--汇编源码

    /* 松瀚 SN8P2501B 定时器初始化程序 */ INI_IRQ: ;定时器T0初始化 MOV A, #01100000b ;定时器模式Fcpu/4 16M/4/4=1M 1U计一次 B0MOV ...