zoukankan      html  css  js  c++  java
  • vc2015编译protobuf

    下载地址:https://github.com/google/protobuf

    1.编译
    通过cmake生成sln文件来编译
    用cmd命令 cd 到3.0.0-beta-4cmake

    mkdir build & cd build
    mkdir solutionx86 & cd solutionx86
    cmake -G "Visual Studio 14 2015" -DCMAKE_INSTALL_PREFIX=../../../../install ../.. -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_SHARED_LIBS=ON -DCMAKE_GENERATOR_TOOLSET=v140_xp
    

    如果要编译64位的话

    cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=../../../../install ../.. -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_BUILD_SHARED_LIBS=ON -DCMAKE_GENERATOR_TOOLSET=v140_xp
    

    注意中间不能有回车之类的,该命令行生成的是dll版本的(静态库的话要注意lib的运行库),其它版本请查考cmake目录下面的README.md

    2.hello world

    将examples目录下满的addressbook.proto,拷贝到生成的protoc.exe目录下面,cd到该目录

    protoc --cpp_out=./ addressbook.proto

    这样就会生成addressbook.pb.cc , addressbook.pb.h  两个文件,包含到你的项目中

    addressbook.pb.cc,需要取消预编译头或者手动加入#include "stdafx.h"

    然后包含头文件和lib文件

    直接用examples目录下面的 add_person.cc里面的代码测试即可

    注意:使用dll的时候需要定义宏PROTOBUF_USE_DLLS,小心不要将这个PROTOBUF_USE_DLLS定义在stdafx.h里面,然后你又取消了预编译头!

  • 相关阅读:
    ASP.NET 下载文件方式
    分享各大平台接口(空间,微博)
    BitmapToASCii
    C#操作进程(Process)
    Config ConnectionStrings
    Import Excel void (NPOI)
    C# Serialize
    C# 属性
    调用存储过程的方法
    Redis配置与安装
  • 原文地址:https://www.cnblogs.com/ultracpp/p/5726968.html
Copyright © 2011-2022 走看看