MAC上如何安装protocolBuf工具

来源:互联网 发布:上海政务数据资源网 编辑:程序博客网 时间:2024/05/16 08:24

在网上游荡很久,也试了很久,都被坑,最后查了多方资料安装成功

一开始我是按照http://m.blog.csdn.net/article/details?id=44244687 来安装,发现brew install automake 报错,

automake-1.15 already installed, it's just not linked  说是已安装,但是没有链接,我也是醉了,然后我想重新安装brew,发现需要翻墙,果断放弃,然后yongcurl 命令来安装

curl -Ohttp://mirrors.kernel.org/gnu/m4/m4-1.4.13.tar.gz
tar -xzvf m4-1.4.13.tar.gz
cd m4-1.4.13
./configure --prefix=/usr/local
make
sudo make install
cd ..
curl -Ohttp://mirrors.kernel.org/gnu/autoconf/autoconf-2.65.tar.gz
tar -xzvf autoconf-2.65.tar.gz
cd autoconf-2.65
./configure --prefix=/usr/local # ironic, isn't it?
make
sudo make install
cd ..
# here you might want to restart your terminal session, to ensure the new autoconf is picked up and used in the rest of the script
curl -Ohttp://mirrors.kernel.org/gnu/automake/automake-1.11.tar.gz
tar xzvf automake-1.11.tar.gz
cd automake-1.11
./configure --prefix=/usr/local
make
sudo make install
cd ..
curl -Ohttp://mirrors.kernel.org/gnu/libtool/libtool-2.2.6b.tar.gz
tar xzvf libtool-2.2.6b.tar.gz
cd libtool-2.2.6b
./configure --prefix=/usr/local
make
sudo make install

成功了

git clone https://github.com/alexeyxo/protobuf-objc.git

./build.sh

从github下载protobuf-objc这个工程,build脚本里面做的是编译。

我建议不要用 ./build.sh ,我安装过程中发现未知错误最终没有进行下去。哎,好失败。懂脚本的朋友可以尝试下。

到此,我们先得感谢 http://www.2cto.com/kf/201503/382440.html的文章作者。点开链接的朋友会发现,这都什么吗,明显照抄人家的。。。

我只能说,该作者前半部分解释的非常好,我是超越不了了,只能完全借用了。其实说白了,就是懒。言归正传:

当我们 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/目录下。


以为可以了,但是我在./configure错误一直都过不去

make 也过不去

哎!!!


使用的是  https://github.com/mingchen/protobuf-ios  首先是下载下来
它其中使用到得命令行 
$ cd compiler$ ./autogen.sh$ ./configure$ make$ make install (optional)
这个就可以,虽然会有些报错,但是可以忽略。现在完成插件的安装了,让我们测试下

新建个proto文件夹

新建msg.proto文件,内容:

package csdnblog;


message PBUser {


required string userId = 1;                       // 用户ID
optional string nick = 2;                         // 用户昵称
optional string avatar = 3;                       // 用户头像


optional string password = 7;
optional string email = 8;
optional string mobile = 9;                       // 手机号码
optional string qqOpenId = 10;                    // QQ ID
optional string sinaId = 11;                      // SINA UserID
optional string weixinId = 12;                    // WeChat UserID
}

cd ~/proto

protoc --proto_path=. --objc_out=. msg.proto

你会看到pb.h和pb.m文件

大功告成~  哈哈哈哈哈哈哈哈哈哈哈

0 0