zoukankan      html  css  js  c++  java
  • 安装指定的Protobuf版本到Mac-Protobuf2.6.1

    最近新项目用到了Protobuf来储存数据,安装时遇到了不少坑,网上也有很多把Protobuf集成到iOS系统上但是坑很多

    下边总结一下安装流程:

    查看官方文档
    源码在 https://github.com/google/protobuf , 如果不想自己编译获得最新版本,则可以下载官方编译好的各个平台的,下载地址:https://github.com/google/protobuf/releases找到自己需要的版本,例如要装2.6.1的话下载protobuf-2.6.1.zip

    第一步:cd /Users/sddd/Downloads/protobuf-2.6.1

    第二步:运行 ./configure

    第三步:运行 make

    第四步:运行 make check

    第五步:运行 make install

    如何没有权限的话,在前边加上sudo

    第六步:

    是依赖库
    git clone https://github.com/alexeyxo/protobuf-objc.git 完成后

    cd ~/protobuf-objc

    ./autogen.sh

    ./configure

    ~/protobuf-objc其实就是刚刚clone的文件目录

    进行./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.

    仔细看,不难发现终端给出了解决办法,我想这应该是跟系统是不是64位有关吧(个人猜测)。

    ./configure CXXFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib

    运行通过后,

    make

    make install

    最终生成的插件名字为protoc-gen-objc,会被安装到/usr/local/bin/目录下。

    你可以

    cd /usr/local/bin/

    ls -a

    按照我的方法,肯定能看见protoc-gen-objc。

    如果没有make命令的话:

    brew -v

    如果没有安装的话ruby -e $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)

    brew install automake
    brew install libtool

    到这里就可以安装成功了,具体集成到项目上可以查看转发的博客上

    在终端protoc --version

     接下来是如何编译一个proto的文件

    1: 打开终端: cd 到放proto的文件夹下
    2:输入命令:protoc --plugin=/usr/local/bin/protoc addressbook.proto --cpp_out="./" 这个是生成c++ .h .cc文件
    3:输入命令:protoc --plugin=/usr/local/bin/protoc addressbook.proto --objc_out="./" 这个是生成oc .h .m 文件
     
    如果要安装最新版本的话,下面还有一个方案
     

    首先:打开终端

    brew -v

    如果没有安装的话ruby -e $(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)

    brew install automake
    brew install libtool
    brew install protobuf
    就是利用brew下载安装了。protobuf就是我们想要的,另外两个是依赖库
    接着
    git clone https://github.com/alexeyxo/protobuf-objc.git 完成后

    cd ~/protobuf-objc

    ./autogen.sh

    ./configure

    ~/protobuf-objc其实就是刚刚clone的文件目录

    进行./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.

    仔细看,不难发现终端给出了解决办法,我想这应该是跟系统是不是64位有关吧(个人猜测)。

    ./configure CXXFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib

    运行通过后,

    make

    make install

    最终生成的插件名字为protoc-gen-objc,会被安装到/usr/local/bin/目录下。

    你可以

    cd /usr/local/bin/

    ls -a

    按照我的方法,肯定能看见protoc-gen-objc。

    一切准备就绪,我们来测试下。

    在桌面创建一个 ProtoBuf的文件夹。然后

    cd ~/Desktop/ProtoBuf

    protoc --plugin=/usr/local/bin/protoc-gen-objc person.proto --objc_out=./

    protoc会自动在/usr/local/bin/目录下寻找名为”protoc-gen-objc”的插件,并使用该插件编译.proto文件,最终生成两个文件:

    Person.pb.h

    Person.pb.m

    推荐比较好的博客:

     

    http://www.jianshu.com/p/d5642a7d1e10?nomobile=yes

     

    http://www.jianshu.com/p/cbbb0bfd0bb6

     
     
  • 相关阅读:
    Navicat 远程连接ubuntu出现的问题
    替换 ubuntu 自带的python版本
    xpath疑惑
    xpath中返回值问题
    AttributeError: 'unicode' object has no attribute 'xpath'
    linux下mysql忘记密码解决方案
    IntelliJ idea常用快捷键
    最近的说明(本篇不谈具体技术,看技术的可以忽略)
    常用的排序算法介绍和在JAVA的实现(二)
    mysql数据库查询过程探究和优化建议
  • 原文地址:https://www.cnblogs.com/y16879w/p/7717936.html
Copyright © 2011-2022 走看看