{"id":144,"date":"2012-09-08T02:27:57","date_gmt":"2012-09-07T18:27:57","guid":{"rendered":"http:\/\/sinofool.net\/blog\/?p=144"},"modified":"2016-10-03T02:20:49","modified_gmt":"2016-10-02T18:20:49","slug":"build-google-protobuf-2-4-1-for-ios-development","status":"publish","type":"post","link":"https:\/\/sinofool.net\/blog\/archives\/144","title":{"rendered":"Build Google protobuf 2.4.1 for iOS development"},"content":{"rendered":"<p>Although iOS5 shipped with a private version of protobuf but it is too old for me.<br \/>\nHere is the script I used to build protobuf.<br \/>\n1. Download the newest protobuf(2.4.1 at the moment) and unpack.<br \/>\n2. Run this in the unpacked directory. It will create a folder named &#8220;protobuf_dist&#8221; on desktop.<br \/>\n3. Copy or add protobuf_dist to xcode project. That&#8217;s all.<br \/>\n<code lang=\"bash\">#!\/bin\/bash<\/p>\n<p>TMP_DIR=\/tmp\/protobuf_$$<\/p>\n<p>###################################################<br \/>\n# Build i386 version first,<br \/>\n# Because arm needs it binary.<br \/>\n###################################################<\/p>\n<p>CFLAGS=-m32 CPPFLAGS=-m32 CXXFLAGS=-m32 LDFLAGS=-m32 .\/configure --prefix=${TMP_DIR}\/i386 \\<br \/>\n\t--disable-shared \\<br \/>\n\t--enable-static || exit 1<br \/>\nmake clean || exit 2<br \/>\nmake -j8 || exit 3<br \/>\nmake install || exit 4<\/p>\n<p>###################################################<br \/>\n# Build armv7 version,<br \/>\n###################################################<\/p>\n<p>SDKROOT=\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/SDKs\/iPhoneOS5.1.sdk<br \/>\nDEVROOT=\/Applications\/Xcode.app\/Contents\/Developer\/Platforms\/iPhoneOS.platform\/Developer<\/p>\n<p>export CC=${DEVROOT}\/usr\/bin\/llvm-gcc<br \/>\nexport CFLAGS=\"-arch armv7 -isysroot $SDKROOT\"<\/p>\n<p>export CXX=${DEVROOT}\/usr\/bin\/llvm-g++<br \/>\nexport CXXFLAGS=\"$CFLAGS\"<br \/>\nexport LDFLAGS=\"-isysroot $SDKROOT -Wl,-syslibroot $SDKROOT\"<\/p>\n<p>.\/configure --prefix=$TMP_DIR\/armv7 \\<br \/>\n\t--with-protoc=${TMP_DIR}\/i386\/bin\/protoc \\<br \/>\n\t--disable-shared \\<br \/>\n\t--enable-static \\<br \/>\n\t-host=arm-apple-darwin10 || exit 1<br \/>\nmake clean || exit 2<br \/>\nmake -j8 || exit 3<br \/>\nmake install || exit 4<\/p>\n<p>###################################################<br \/>\n# Packing<br \/>\n###################################################<\/p>\n<p>DIST_DIR=$HOME\/Desktop\/protobuf_dist<br \/>\nrm -rf ${DIST_DIR}<br \/>\nmkdir -p ${DIST_DIR}<br \/>\nmkdir ${DIST_DIR}\/{bin,lib}<br \/>\ncp -r ${TMP_DIR}\/armv7\/include ${DIST_DIR}\/<br \/>\ncp ${TMP_DIR}\/i386\/bin\/protoc ${DIST_DIR}\/bin\/<br \/>\nlipo -arch i386 ${TMP_DIR}\/i386\/lib\/libprotobuf.a -arch armv7 ${TMP_DIR}\/armv7\/lib\/libprotobuf.a -output ${DIST_DIR}\/lib\/libprotobuf.a -create<br \/>\n<\/code><\/p>\n<p>This is tested on OSX Lion with Xcode 4.2.1<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Although iOS5 shipped with a private version of protobuf but it is too old for me. Here is the script I used to build protobuf. 1. Download the newest protobuf(2.4.1 at the moment) and unpack. 2. Run this in the unpacked directory. It will create a folder named &#8220;protobuf_dist&#8221; on desktop. 3. Copy or add [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"activitypub_content_warning":"","activitypub_content_visibility":"","activitypub_max_image_attachments":4,"activitypub_interaction_policy_quote":"anyone","activitypub_status":"","footnotes":""},"categories":[15,5],"tags":[],"class_list":["post-144","post","type-post","status-publish","format-standard","hentry","category-ios","category-tech"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/sinofool.net\/blog\/wp-json\/wp\/v2\/posts\/144","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sinofool.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sinofool.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sinofool.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sinofool.net\/blog\/wp-json\/wp\/v2\/comments?post=144"}],"version-history":[{"count":6,"href":"https:\/\/sinofool.net\/blog\/wp-json\/wp\/v2\/posts\/144\/revisions"}],"predecessor-version":[{"id":158,"href":"https:\/\/sinofool.net\/blog\/wp-json\/wp\/v2\/posts\/144\/revisions\/158"}],"wp:attachment":[{"href":"https:\/\/sinofool.net\/blog\/wp-json\/wp\/v2\/media?parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sinofool.net\/blog\/wp-json\/wp\/v2\/categories?post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sinofool.net\/blog\/wp-json\/wp\/v2\/tags?post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}