天天看点

【Protocol Buffer】Protocol Buffer入门教程(八):Windows平台部署Protobuf环境

00. 目录

01. protobuf源码下载

02. 安装cmake

03. 生成动态库

04. 添加环境变量

05. 附录

csdn下载:javascript:void(0)

下载网址:https://github.com/protocolbuffers/protobuf/releases

【Protocol Buffer】Protocol Buffer入门教程(八):Windows平台部署Protobuf环境

2.1 cmake介绍

cmake这个名字是“cross platform make”的缩写 。 cmake是一个跨平台的安装编译工具,可以用简单的语句来描述所有平台的安装(编译过程)。他能够输出各种各样的makefile或者project文件,能测试编译器所支持的c++特性,类似unix下的automake。只是 cmake 的组态档取名为 cmakelists.txt。cmake 并不直接建构出最终的软件,而是产生标准的建构档(如 unix 的 makefile 或 windows visual c++ 的 projects/workspaces),然后再依一般的建构方式使用。这使得熟悉某个集成开发环境(ide)的开发者可以用标准的方式建构他的软件,这种可以使用各平台的原生建构系统的能力是 cmake 和 scons 等其他类似系统的区别之处。

2.2 cmake安装

相关安装方法请参考: 【tools】windows安装cmake工具

3.1 解压protobuf-cpp-3.10.0.zip到d盘

【Protocol Buffer】Protocol Buffer入门教程(八):Windows平台部署Protobuf环境

注意:路径中不要有中文。

3.2 打开cmake工具

【Protocol Buffer】Protocol Buffer入门教程(八):Windows平台部署Protobuf环境

3.3 设置源码路径和生成项目的路径

选择配置

【Protocol Buffer】Protocol Buffer入门教程(八):Windows平台部署Protobuf环境

3.4 选择vs版本和编译器

【Protocol Buffer】Protocol Buffer入门教程(八):Windows平台部署Protobuf环境

3.5 选择生成对应对应的库

【Protocol Buffer】Protocol Buffer入门教程(八):Windows平台部署Protobuf环境

3.6 生成成功

【Protocol Buffer】Protocol Buffer入门教程(八):Windows平台部署Protobuf环境

然后选择open project,默认使用vs2017打开该项目。

3.7 编译项目生成库文件

【Protocol Buffer】Protocol Buffer入门教程(八):Windows平台部署Protobuf环境

在 vs2017工程目录<code>/debug</code>目录下,可以看到生成的库文件

【Protocol Buffer】Protocol Buffer入门教程(八):Windows平台部署Protobuf环境

将生成的动态库和头文件放到自定义目录中备用,在vs中设置头文件和库的路径。

修改预处理器定义:

项目属性-&gt;c/c++ -&gt; 预处理器 -&gt; 预处理器定义 添加这个<code>protobuf_use_dlls</code>宏定义

4.1 将上面整理好的sdk放在c盘中

【Protocol Buffer】Protocol Buffer入门教程(八):Windows平台部署Protobuf环境

4.2 设置环境变量

鼠标右击此电脑–&gt; 属性 --&gt; 高级系统设置 --&gt; 环境变量

【Protocol Buffer】Protocol Buffer入门教程(八):Windows平台部署Protobuf环境

新建两个环境变量

【Protocol Buffer】Protocol Buffer入门教程(八):Windows平台部署Protobuf环境

4.3 测试

【Protocol Buffer】Protocol Buffer入门教程(八):Windows平台部署Protobuf环境

到此windows平台部署protobuf环境已经成功了。

sdk下载:sdk-protobuf3.10.rar