Windows下配置Protobuf
来源:互联网 发布:directx11编程 编辑:程序博客网 时间:2024/06/06 04:40
版本是 protobuf-2.6.1,编译工具使用Visual Studio 2010
安装编译protobuf
Windows下,需要下载两个包protobuf-2.6.1.tar.gz和protoc-2.6.1-win32.zip,将两个包解压到E:\protobuf,在E:\protobuf\protobuf-2.6.1\vsprojects下有protobuf.sln这个文件,用VS2010打开,得到9个解决方案。
在Solution ‘protobuf’(9 projects)上右键,点击Build Solution生成我们需要的文件。
完成这一步后,会在E:\protobuf\protobuf-2.6.1\vsprojects\Debug下出现很多内容,最重要的几个就是:libprotobuf.lib,libprotobuf-lite.lib,libprotoc.lib,lite-test.exe,protoc.exe,test_plugin.exe,tests.exe。
(注意:编译的debug版本的lib,要对应工程的debug版,如果工程是release,最好对应release版本的lib)
编译.proto文件
运行编译器,指定源目录和目标目录,定位你的 .proto 文件到源目录,然后执行:
protoc -I=$SRC_DIR --cpp_out=$DST_DIR ***.proto
例:使用cmd运行protoc.exe生成我们的目标语言格式(c++),假设现在有E:\protobuf\protobuf-2.6.1\examples\test.proto,输入命令行:
protoc -I=E:\protobuf\protobuf-2.6.1\examples --cpp_out=E:\protobuf\protobuf-2.6.1\examples E:\protobuf\protobuf-2.6.1\examples\test.proto(cpp_out表示生成C++代码,cpp_out等号后面第一个路径指生成文件的存放路径,第二个指.proto文件的绝对路径)
配置工程属性
在工程中导入生成的.pb.c和.pb.h文件后,我们需要配置工程使用protobuf的头文件和lib文件的路径,右键工程-属性:
C/C++ - 常规 - 附加包含目录,导入这个路径E:\protobuf\protobuf-2.6.1\src链接器 - 常规 - 附加库目录,导入这个路径E:\protobuf\protobuf-2.6.1\vsprojects\Debug
在项目中使用protobuf时,需在源代码中包含:
#pragma comment(lib,"libprotobuf.lib")#pragma comment(lib,"libprotoc.lib")
(注:本文中的安装路径均为我个人的安装路径)
- Windows下配置Protobuf
- protobuf入门详解(在windows下配置protobuf)
- Windows下QT Creator配置protobuf
- 【Game】protobuf:windows下环境配置
- protobuf windows 下的使用配置
- Google protobuf :windows下环境配置
- windows 下 protobuf 使用
- windows下使用protobuf
- windows下编译protobuf
- google protobuf学习笔记一:windows下环境配置
- google protobuf学习笔记一:windows下环境配置
- google protobuf学习笔记一:windows下环境配置
- google protobuf学习笔记一:windows下环境配置
- Ubuntu 下配置protobuf
- Ubuntu 下配置protobuf
- Ubuntu 下配置protobuf
- Ubuntu 下配置protobuf
- Windows下VC++使用protobuf
- Java中移位运算
- find your present (2) (位异或)
- 更改ssh服务远程登录的配置
- MySQL中针对大数据量常用技术:查询优化,数据转移
- 暑期打卡——Ubuntu下的java web开发环境搭建(eclipse+tomcat+mysql+jdk)
- Windows下配置Protobuf
- 单例模式(懒汉方式和饿汉方式)
- PHP基础排序算法(四)快速排序
- SDUT 3467 图的基本存储的基本方式四
- Quartz(07) quartz spring web 项目的整合(方法一)
- Git暂存区原理
- LeetCode | Construct Binary Tree from Preorder and Inorder Traversal
- Drupal7函数之drupal_get_messages()
- Hive集成HBase详解