Huy Tran
Huy Tran

Reputation: 217

Compile protobuf with xCode 5

I want to use protobuf(https://code.google.com/p/protobuf/) in my project

Did you successfully compile protobuf with xCode 5, Please help to share your experience?

Thanks.

Upvotes: 6

Views: 6667

Answers (2)

Bennett Smith
Bennett Smith

Reputation: 501

If you don't mind building Google Protobuf yourself then a good alternative to using Cocoapods is to run the bash script here.

https://gist.github.com/BennettSmith/7150245

This script will produce a proper build of Google Protobuf that supports the i386, armv7, armv7s, arm64 and x86_64 architectures. It will produce a static library that is universal. It will also produce the protoc compiler for use on OS X.

Upvotes: 10

Bennett Smith
Bennett Smith

Reputation: 501

You can add support for Google Protocol Buffers to an Xcode 5 project using Cocoapods by adding the following line to your Podfile.

pod 'GoogleProtobuf', '~> 2.5.0'

This will place the C++ version of the protobuf code into a Pod for your project. It will also add the protoc compiler in the folder Pods/GoogleProtobuf/bin/protoc within your project.

You can create a custom build rule in your project that automatically converts the .proto files into .ph.{h,cc} files. Here is how I did that:

Setup a build rule to "Process Source files with names matching: *.proto Using Custom Script". The script should include the following:

cd ${INPUT_FILE_DIR}
${SRCROOT}/Pods/GoogleProtobuf/bin/protoc --proto_path=${INPUT_FILE_DIR} ${INPUT_FILE_PATH} --cpp_out=${INPUT_FILE_DIR}/cpp

Set the output files to include the following:

$(INPUT_FILE_DIR)/cpp/$(INPUT_FILE_BASE).pb.h
$(INPUT_FILE_DIR)/cpp/$(INPUT_FILE_BASE).pb.cc

Any .proto files you include in your project will now automatically be converted to C++ and then compiled as part of your build.

Upvotes: 11

Related Questions