Compile protobuf with xCode 5

后端 未结 2 1611
面向向阳花
面向向阳花 2020-12-15 01:38

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? <

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-15 02:23

    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.

提交回复
热议问题