环境安装

1:下载CMake

2:打开VS Command Prompt

3:修改工作目录到目标目录

cd C:\Path\to

4:创建编译完后 protobuf headers/libraries/binaries 将要安装的文件夹

C:\Path\to>mkdir install

5:确保 'cmake' 命令可用,(如果不可用确保 把它加入到 path 环境变量中)

set PATH=%PATH%;D:\Program Files\cmake-3.5.2-win32-x86\bin

6:确保Git命令可用(如果不可用,添加到到 path 环境变量)

set PATH=%PATH%;D:\Program Files\Git\cmd

源设置

下载 packages https://github.com/google/protobuf/releases

把protobuf 放入  C:\Path\to 目标

cd  C:\Path\to\protobuf\cmake

CMake 配置

参考: Visual Studio Generators

注意:64位请用对应的 64位VS命令行

1:创建一个 build 目录,并且改变当前工作目录到build

mkdir build & cd build

------创建Release配置

C:\Path\to\protobuf\cmake\build>mkdir release & cd release

C:\Path\to\protobuf\cmake\build\release>cmake -G "NMake Makefiles" ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_INSTALL_PREFIX=../../../../install ^
../..

------创建Debug 配置

C:\Path\to\protobuf\cmake\build>mkdir debug & cd debug
C:\Path\to\protobuf\cmake\build\debug>cmake -G "NMake Makefiles" ^
-DCMAKE_BUILD_TYPE=Debug ^
-DCMAKE_INSTALL_PREFIX=../../../../install ^
../..

-----创建Visual Studio 解决方案文件

C:\Path\to\protobuf\cmake\build>mkdir solution & cd solution
C:\Path\to\protobuf\cmake\build\solution>cmake -G "Visual Studio 11 2012 Win64" ^

-DCMAKE_INSTALL_PREFIX=../../../../install ^
-Dprotobuf_BUILD_TESTS=OFF ^
../..

备注

Generates Visual Studio 11 (VS 2012) project files.

Visual Studio 11 2012 Win64  --Specify target platform x64.

Visual Studio 11 2012 ARM   --Specify target platform ARM.

Visual Studio 11 2012 <WinCE-SDK>  --Specify target platform matching a Windows CE SDK name.

Generates Visual Studio 12 (VS 2013) project files:

Visual Studio 12 2013 Win64  --Specify target platform x64.

Visual Studio 12 2013 ARM     --Specify target platform ARM.

Generates Visual Studio 14 (VS 2015) project files:

Visual Studio 11 2012 Win64  --Specify target platform x64.

Visual Studio 11 2012 ARM   --Specify target platform ARM.

Visual Studio 11 2012 <WinCE-SDK>  --Specify target platform matching a Windows CE SDK name.

编译

To compile protobuf:

C:\Path\to\protobuf\cmake\build\release>nmake

或者

C:\Path\to\protobuf\cmake\build\debug>nmake

或者

VS:打开生成的.sln 文件 即可。

如果出现如下错误:

 

修改Platform Toolset 即可

安装

To install protobuf to the specified *install* folder:

C:\Path\to\protobuf\cmake\build\release>nmake install

or

C:\Path\to\protobuf\cmake\build\debug>nmake install

或者编译VS解决方案中的“INSTALL”。

如果出现编译错误,尝试用管理员权限打开VS重新试试

定义消息体

package tutorial;

message Person {
required string name = ;
required int32 id = ;
optional string email = ; enum PhoneType {
MOBILE = ;
HOME = ;
WORK = ;
} message PhoneNumber {
required string number = ;
optional PhoneType type = [default = HOME];
} repeated PhoneNumber phone = ;
} message AddressBook {
repeated Person person = ;
}

编译生成对应library

c++:(protoc -I=$SRC_DIR --cpp_out=$DST_DIR $SRC_DIR/addressbook.proto)

protoc -I=. --cpp_out=. HookMessage.proto

生成对应的 .h 和.cpp 文件

c#:(protoc -I=$SRC_DIR --csharp_out=$DST_DIR $SRC_DIR/addressbook.proto)

生成.cs 文件

c++项目使用

1:添加protobuf头文件:   protobuf下的Src (protobuf-3.0.0-beta-2\src)

Property-->Configuration Properties-->c/c++-->General:Additional Include Directories

2:添加类库文件 (上面build出来的类库,如上例:C:\Path\to\protobuf\cmake\build\debug)

Property-->Configuration Properties-->Linker-->General-->Additional Library Directories

在使用cpp文件顶部加上

#pragma comment(lib, "libprotobufd.lib")
#pragma comment(lib, "libprotocd.lib")

build项目:

可能提示错误

该错误又由于 生成的类库和当前的项目使用的是不一样的 Runtime Library

修改如下配置即可: Property-->Configuration Properties-->c/c++-->Cide Generation-->Runtime Library(   Multi-threaded DLL (/MD)  |  Multi-threaded Debug (/MTd)  等)

C#项目使用

引用Google.Protobuf.dll        protobuf 源包中C#项目生成的DLL(需要打开项目自己编译生成)

window 安装 Protobuf的更多相关文章

  1. 解决Bash On Ubuntu On Window安装Zsh无效问题附安装说明

    前言 Zsh是一款非常棒的Shell,使用Linux和Mac系统的人,基本上都知道zsh的存在. 问题 在安装完Zsh后,zsh是可以使用的,但是重启之后,又恢复至默认的bash. 我在安装好之后,使 ...

  2. MAC 安装 Protobuf

    1.确认MAC装有g++.make.vim工具 2.安装make工具使用       brew install make 3.安装protobuf brew install protobuf 4.安装 ...

  3. Linux下安装protobuf并实现简单的客户端服务器端通信

    http://code.google.com/p/protobuf/downloads/list上可以下载Protobuf的源代码. 安装步骤如下所示: 1>tar -xzf protobuf- ...

  4. mac 安装protobuf,并编译

    因公司接口协议是PB文件,需要将 PB 编译成JAVA文件,且MAC 电脑,故整理并分享MAC安装 google 下的protobuf 文件   MAC 安装protobuf 流程 1.下载 http ...

  5. python3.4学习笔记(二十四) Python pycharm window安装redis MySQL-python相关方法

    python3.4学习笔记(二十四) Python pycharm window安装redis MySQL-python相关方法window安装redis,下载Redis的压缩包https://git ...

  6. MOTT介绍(2)window安装MQTT服务器和client

    MQTT目录: MQTT简单介绍 window安装MQTT服务器和client java模拟MQTT的发布,订阅 window安装MQTT服务器,我这里下载了一个apache-apollo-1.7.1 ...

  7. RabbitMQ(一):Window安装RabbitMQ

    原文:RabbitMQ(一):Window安装RabbitMQ 1.安装ERLANG语言环境 由于RabbitMQ是采用Erlang编写的,因此我们需要先安装该语言库,以便运行代理服务器.从Erlan ...

  8. MySQL Community Server 5.5.56 ZIP Archive 绿色解压版 window安装步骤

    MySQL Community Server 5.5.56  ZIP Archive  绿色解压版 window安装步骤 首先 准备好启动配置文件my.ini [mysqld] #设置字符集为utf8 ...

  9. linux下安装protobuf及cmake编译

    一.protobuf 安装 protobuf版本:2.6.1 下载地址:https://github.com/google/protobuf/archive/v2.6.1.zip 解压之后进入目录 修 ...

随机推荐

  1. Yii处理流程

    Yii的应用程序处理流程 用户访问URL http://www.example.com/blog/index.php?r=site/contact 1.入口脚本被网站服务器执行以处理此请求. 2.一个 ...

  2. windows桌面添加右键环境

    1.组合键win + R,输入regedit,回车   打开注册表编辑器 2.找到目录中[HKEY_CLASSES_ROOT\Directory\Background\shell]对其右键,新建一个项 ...

  3. UVA_393_Doors_(计算几何基础+最短路)

    描述 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page ...

  4. WordPress Comment Attachment插件跨站脚本漏洞

    漏洞名称: WordPress Comment Attachment插件跨站脚本漏洞 CNNVD编号: CNNVD-201310-062 发布时间: 2013-10-09 更新时间: 2013-10- ...

  5. 使用 Puppet 在 Windows Azure 中配备 Linux 和 Windows 环境

     发布于 2013-12-11 作者 Ross Gardler 微软开放技术有限公司 (MS Open Tech) 很高兴地宣布发行新的 Windows Azure Puppet 模块.通过这个模 ...

  6. EasyUI的增删查改(后台ASP.NET)

    转自:http://www.cnblogs.com/dedeyi/archive/2013/04/22/3035057.html 某某人曾经跟我说,你们做系统不就是增删查改吗. 是啊,很多时候我们就是 ...

  7. (转载)C++中将构造函数或析构函数定义为private

    (转载)http://www.blogjava.net/fhtdy2004/archive/2009/05/30/278971.html C++中将构造函数或析构函数定义为private 很多情况下要 ...

  8. HttpServletRequest、request常用方法、request常见应用、请求转发、RequestDispatcher

        HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求头中的所有信息都封装在这个对象中,开发人员通过这个对象的方法,可以获得客户这些信息. ...

  9. 最小生成树之Prim算法,Kruskal算法

    Prim算法 1 .概览 普里姆算法(Prim算法),图论中的一种算法,可在加权连通图里搜索最小生成树.意即由此算法搜索到的边子集所构成的树中,不但包括了连通图里的所有顶点(英语:Vertex (gr ...

  10. Linux 单网卡多 IP 的配置方法

     Linux 单网卡多 IP 的配置方法 1 .永久配置的方法: 知道在 Linux 下网卡被称为 eth0,eth1,eth2..... ,所有网卡的配置文件都存储在 /etc/sysconfi ...