cocos2d-x protobuf; cocos2dx protocol buffer


昨日プロジェクトがprotocol bufferを使うことを知りました.今晩見て、protobufが本質的に情報表現プロトコル+編集、解析ライブラリであることを知りました.
linuxオープンソースソフトウェアはすべて1つのモードで、先に./configure --help > build.shあれらのものがあることを见て、更にconfigure make.. 
公式サイトのドキュメントに基づいて簡単なwriteを作って、readのtestは大体どんな状況なのかを理解します.
OK、ここまでprotocol bufferを使っています.次にcocos 2 dxにコンパイルします.
本質的には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、 は は1つの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).
これはすでに して、 なcocos 2 dx はすでにアップロードして、 を てurlをダウンロードします.ダウンロード 、 できます. はコンソールメッセージを してください.
http://download.csdn.net/detail/chenee543216/5803917
2、Android version protobuf   
は がありましたが、まだandroidを る がありません.
Androidの でiOSのように にlibprotobufをコンパイルすることができます.a、また でこれを び します.a,しかし、これは には であることに づいたので、 ったほうがいい.ccファイルが に わったAndroid.mk.どうせコンパイルするaファイルもこの に います.
のやり はsrc/googleディレクトリを projに てることです.Android/jni/ はAndroid.mkは すればいいです.linuxの でMakefileを って を します( はvsとxcodeはすべて じです)、このようにMakefileの で したファイルだけがコンパイルされるので、 のgoogle/ディレクトリの のものは のことは にしません.
--------- なandroidプロジェクトはiosとの を っている.
http://download.csdn.net/detail/chenee543216/5811221
-----------------------------Android.mk----------
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := game_shared

LOCAL_MODULE_FILENAME := libgame

LOCAL_SRC_FILES := hellocpp/main.cpp \
                   ../../Classes/AppDelegate.cpp \
                   ../../Classes/HelloWorldScene.cpp \
                   ../../Classes/lm.helloworld.pb.cpp \
./google/protobuf/stubs/common.cc                              \
./google/protobuf/stubs/once.cc                                \
./google/protobuf/extension_set.cc                             \
./google/protobuf/generated_message_util.cc                    \
./google/protobuf/message_lite.cc                              \
./google/protobuf/repeated_field.cc                            \
./google/protobuf/wire_format_lite.cc                          \
./google/protobuf/io/coded_stream.cc                           \
./google/protobuf/io/zero_copy_stream.cc                       \
./google/protobuf/io/zero_copy_stream_impl_lite.cc

LOCAL_CPP_EXTENSION=.cc .cpp

#LOCAL_LDFLAGS = /tmp/libprotobuf.a
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes

LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static

include $(BUILD_SHARED_LIBRARY)

$(call import-module,CocosDenshion/android) \
$(call import-module,cocos2dx) \
$(call import-module,extensions)

3、to simplify these steps
このようにして、みんなはすでに っていて、 はprotobuf-liteにとって、いくつかのファイルの だけで、その でuもこのいくつかのファイルを することはできません.だからいっそ の として きずり んでしまった.しかもすべてcppコードで、プラットフォームにまたがって、メンテナンスしやすくて、“お さんは と のコードを する はありません.”
for the last ,I will upload a cocos2dx project that include iOS/simulator/android versions.
done
TO Be Continue ...