windows-protoc buffer

本文是转载别人文章,文章出是http://kuaile.in/archives/1214

当前位置:  首页 >  编程技术 > 正文

windows下Google Protocol Buffer 编译安装教程

width="728" height="90" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" id="aswift_0" name="aswift_0" style="border-width: 0px; border-style: initial; margin: 0px; padding: 0px; left: 0px; position: absolute; top: 0px;">

    protobuf的全称是Protocol Buffer,它是google 的一种数据交换的格式,可用于用于分布式应用之间的数据通信或者异构环境下的数据交换,

    最近因为项目的需求,需要接触Protobuf,在官方提供的压缩包中,提供了Linux下的编译脚本,但是,由于项目在windows下开发,因此,需要在Windows编译和安装Protobuf,结合自己的探索,希望能够帮助到初次接触到protobuf的朋友

1.下载Google Protocol Buffer源码包

下载可以到protobuf官网下载:http://code.google.com/p/protobuf/downloads/list,一般下载第一个或是第二个,因为第一,二个是源码包,第三个是可执行文件

2.解压压缩包

解压压缩包后,会得到类似于下面的文件列表:

文件列表

3.编译vs工程

  • 在解压后的文件夹中,打开vsprojects目录,目录中的文件如图所示:

vsprotects目录文件

打开libprotobuf.vcproj(这个是vs的工程文件,打开前请确认安装了vs2005 或vs2008,vs2010等等),在打开工程中,   可能需要转换工程,直接转换就行了

打开后,vs的工程页面如图所示:

工程列表

右键分别生成libprotobuflibprotobuf-litelibprotocprotoc这四个工程(编译模式为Release 模式):

  • 生成lib文件

4.编译完成

编译完成后,可以在vsprojects\Release下发现3个lib和一个exe文件,他们分别是libprotobuf.liblibprotobuf-lite.liblibprotoc.libprotoc.exe :

lib文件列表

protoc.exe文件

5.拷贝文件到windows目录下:

将得到的libprotobuf.liblibprotobuf-lite.liblibprotoc.libprotoc.exe拷贝到系统盘的windows目录下。如果你的系统安装在C盘,那么就拷贝到c:\windows目录下

6.编译proto文件,生成c++文件

假设在E:\test目录下有一个名为addressbook.proto的proto文件,那么打开CMD,输入下面的命令就可以生成C++源码了:

?
1
protoc.exe -I=e:\ test --cpp_out=e:\ test e:\ test \addressbook.proto

生成c++源码文件

生成了addressbook.pb.h和addressbook.pb.cc文件,将这个文件拷贝到需要用到的工程里就可以直接用了:
生成源码文件成功

至此,protobuf的编译和使用教程就这么多了,如果有错误的地方,还请多多指出

0
width="728" height="90" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allowfullscreen="true" id="aswift_1" name="aswift_1" style="border-width: 0px; border-style: initial; margin: 0px; padding: 0px; left: 0px; position: absolute; top: 0px;">

本文固定链接: http://kuaile.in/archives/1214 | 蒲公英的博客

该日志由 蒲公英 于2012年10月07日发表在 编程技术 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。 
原创文章转载请注明: windows下Google Protocol Buffer 编译安装教程 | 蒲公英的博客
关键字: ProtobufProtocol Buffer

windows下Google Protocol Buffer 编译安装教程:目前有1 条留言

    发表评论

     

     

     

                          

     

    verify that you are a human,
    drag Pencil into the circle.

    快捷键:Ctrl+Enter

    • 0
      点赞
    • 0
      收藏
      觉得还不错? 一键收藏
    • 0
      评论

    “相关推荐”对你有帮助么?

    • 非常没帮助
    • 没帮助
    • 一般
    • 有帮助
    • 非常有帮助
    提交
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值