Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 997
Huy Tran Avatar asked Oct 18 '13 07:10

Huy Tran


1 Answers

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.

like image 78
Bennett Smith Avatar answered Oct 02 '22 17:10

Bennett Smith