你应该懂得protobuf

作者: 百草纪 | 来源:发表于2017-06-23 16:50 被阅读68次

    本文记录配置环境过程,不介绍使用过程

    protobuf-swift版的安装

    • 这是官方给出的环境配置过程,还有一篇官方专门针对objeswift的配置教程
    • 不要马上就敲啊,待我一步步解说其中的坑点

    1.ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

    2.brew install automake

    3.brew install libtool

    4.brew install protobuf

    5.git clone git@github.com:alexeyxo/protobuf-swift.git

    6../scripts/build.sh

    Add ./src/ProtocolBuffers/ProtocolBuffers.xcodeproj in your project.

    前四步是没有问题的

    • 当我敲到第五步时,记得让我选择yes/no,我选了yes,不知道是不是选错了,结果这句代码失效了,说我没有权限下载该项目
      • 报错:protocol Could not read from remote repository.
    • 对应的解决方法
    • 一:git clone https://github.com/alexeyxo/protobuf-swift.git
    • 如果是OC开发,就把其中的swift改成objc,下同
    • 二:直接手动下载下来,在放在这个位置,记得要把-master删掉
    • 第六步我没有跟着上面的6敲,而是跟着一个博客敲,不过官方另一片文章写的是用./build.sh,试过,好像不灵。没有具体探究过,大家随意
    • 跟着博客走是下面这样
    • cd ~/protobuf-swift
    • ./autogen.sh
    • ./configure
    • 进行./configure可能会报错,不过别着急,先分析错误信息
    configure: error: 
    

    ERROR: protobuf headers are required.
    You must either install protobuf from google,
    or if you have it installed in a custom location
    you must add '-Iincludedir' to CXXFLAGS
    and '-Llibdir' to LDFLAGS.
    If you did not specify a prefix when installing
    protobuf, try
    './configure CXXFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib'
    In some 64-bit environments, try LDFLAGS=-L/usr/local/lib64.

    * 解决方法:`./configure CXXFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib`
    * `make`
    * `make install`
    * 最终生成的插件名字为`protoc-gen-swift`,会被安装到`/usr/local/bin/`目录下。
    * 去看看
    * `cd /usr/local/bin/ `
    * `ls -a`
    
    • 这里配置结束(比官方配置过程复杂一些,你要是没有遇到我遇到的坑,可以跟着官方走)
    • 然后生成protoc文件,用protoc person.proto --swift_out="./"试试有没有效果

    关于ProtocolBuffers-Swift的集成,推荐用Cocoapods集成,你也可以将该项目拖进你的工程直接使用,需要选中对应的库,编译,添加该库到工程,使用。

    swift-protobuf版

    • 看这篇文章足够了
    • 这篇文章 swift的安装是没问题的,OC没试过。
    • 注意
      • 里面有这个指令:git checkout tags/[tag_name]
      • 这里加个注释:git checkout "tags/[tag_name]”(引号内为对应版本)

    这篇文章和上面一篇差不多,内容更多。

    最后,原谅我没时间给大家抠图了!所以对于从来没有接触过的小白可能有些懵逼了!

    相关文章

      网友评论

        本文标题:你应该懂得protobuf

        本文链接:https://www.haomeiwen.com/subject/aficcxtx.html