Google Protobuf - Mac OS X and iOS Support
The script in this gist will help you buid the Google Protobuf library for use with Mac OS X and iOS. Other methods (such as homebrew or direct compilation) have issues that prevent their use. The libraries built by this script are universal and support all iOS device architectures including the simluator.
Get the Script
The easiest way to use this script is to simply clone the gist onto your machine using the following command:
$ git clone https://gist.github.com/9487468ae3375d0db0cc.git build-protobuf
Performing the Build
The script will automatically download the tarball from Google Code, so all you need to do is run the script. This will build the 2.6.1 version of Protobuf. The script understands a few command-line options too.
$ cd build-protobuf
$ ./build-protobuf.sh
Add --interactive
to the above script if you would like the script to stop
after each major operation. This makes it easier to inspect the output from
the various steps for potential errors.
Add --master
if you would prefer to build from the master branch in the
Google Protobuf git repo.
Results
Build results are found in a folder called protobuf-{version}
, where {version}
will be either 2.6.1
or master
. This folder contains bin
, include
and lib
folders.
Integration with Xcode
Create a build rule in your Xcode project with the following settings.
Process *Source files with names matching:* `*.proto`
Using *Custom script:*
cd ${INPUT_FILE_DIR}
${SRCROOT}/Google/protobuf/bin/protoc --proto_path=${INPUT_FILE_DIR} ${INPUT_FILE_PATH} --cpp_out=${DERIVED_FILE_DIR}
Output Files
$(DERIVED_FILE_DIR)/$(INPUT_FILE_BASE).pb.cc
$(DERIVED_FILE_DIR)/$(INPUT_FILE_BASE).pb.h
Depending on where you choose to install the protobuf build, you will
need to adjust the path to protoc
.
FAQ
Can Protobuf be built using libstdc++?
Unfortunately, the protobuf C++ code is not compatible with libstdc++ at the moment.
You must use libc++
instead.
Can you provide a similar script for Android?
No
implicit conversion looses integer precision
warnings?
Why am I gettings all the Unfortunately, the code generated by protoc
is not 64-bit clean. In practice I have not
experienced any issues as a result of this. It would be better if the generated code was
reworked for better 64-bit support. This may come with the 3.0 version they are working
on now.