Google Protocol Buffers浅析(二)
来源:互联网 发布:破解机器码注册软件 编辑:程序博客网 时间:2024/06/06 07:25
网上的教程还是和实际操作有很多区别,在这里把遇到的几个问题分享一下。
1.按照全部步骤完成以后, 如果用Visual Studio 2012编译,会报一个
error C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
的错误,原因不解释了,其实是我自己查了以后也没看太明白,解决方法是在"stdafx.h"文件中加入下面这句define就可以了
#define _SCL_SECURE_NO_WARNINGS
2)编译通过以后链接的时候,会报以下的错误一堆
error LNK2038: 检测到“_ITERATOR_DEBUG_LEVEL”的不匹配项: 值“2”不匹配值“0”
检测到“RuntimeLibrary”的不匹配项: 值“MDd_DynamicDebug”不匹配值“MT_StaticRelease”
导致的原因,按照 1-3 步骤编译出的release版本的lib,在PBTest工程的debug模式下形成了调用release模式编译出的lib文件的问题。
另外2-7步骤选择的Runtime Library也要相同。
----------------------------- 我是华丽的分割线-----------------------
本文开始将逐渐介绍怎么使用protocol buffers来完成序列化与反序列化数据的应用,开发环境为VS2008,语言为C++,外部库用的是googlebuffer库。
1、Google Protocol Buffer库
1)进入网址 https://code.google.com/p/protobuf/downloads/list 下载最新版本Protocol Buffers full source
2)下载解压后进入vsprojects文件夹打开protobuf.sln, 高版本的Visual Studio会转换, 无视, 直接确定完成.
3)右键分别生成libprotobuf,libprotobuf-lite,libprotoc,protoc这四个工程(编译模式为Release 模式)
4)编译完成后,可以在vsprojects\Release下发现3个lib和一个exe文件,他们分别是
libprotobuf.lib,libprotobuf-lite.lib,libprotoc.lib和protoc.exe :
5)将以上文件复制到GoogleProtocolBuffer/lib目录中,将下载文件夹中的src/google文件复制到
GoogleProtocolBuffer/include目录中.
2、建立并正确设置项目
1)将步骤1中的GoogleProtocolBuffer文件夹拷贝到你的项目工程里,如下图所示:
2)使用编译器将定义的proto文件编译成.h与.cc文件,拷贝到项目工程目录下,如下图所示:
3)在项目中将.h与.cc文件引用进来,并在addressbook.pb.cc头部加上一句include "stdafx.h",否则编译时会报错
4)打开项目属性,右键项目->Configuration(配置属性)->C/C++ -》General(常规) ,设置Additional Include Directories(附加包含目录),如下所示:
5)定位到Configuration(配置属性) -> Linker(l链接器) -> General(常规), 设置Additional Library Directories(附加库目录),如下所示
6)定位到Configuration(配置属性) -> Linker(l链接器) -> Input(输入) -> Additional Dependencies(附加依赖项),如下图所示:
7)定位到Configuration(配置属性) -> C/C++-> Code Generation,修改Runtime Library项为Multi-threaded(/MT),如下图所示: 通过上述的一些列项目属性设置,程序可以正确编译通过了,但是什么功能都没有,下篇文章中将介绍怎么序列化与反序列化我们的数据。
- Google Protocol Buffers浅析(二)
- Google Protocol Buffers浅析(二)
- Google Protocol Buffers浅析(二)
- Google Protocol Buffers浅析(二)
- Google Protocol Buffers浅析(二)
- Google Protocol Buffers浅析(二)
- Google Protocol Buffers浅析(二)
- Google Protocol Buffers浅析
- Google Protocol Buffers浅析
- Google Protocol Buffers浅析
- Google Protocol Buffers浅析(一)
- Google Protocol Buffers浅析(三)
- Google Protocol Buffers浅析(四)
- Google Protocol Buffers浅析(一)
- Google Protocol Buffers浅析(三)
- Google Protocol Buffers浅析(四)
- Google Protocol Buffers浅析(一)
- Google Protocol Buffers浅析(三)
- eclipse中文语言包安装
- 每日一记
- Java final修饰符的作用
- LeetCode|3SUM Closest
- 关于有序顺序表的比较的题目
- Google Protocol Buffers浅析(二)
- ~Delphi const 杂谈~
- POJ 1248 Safecracker 水题
- HDFS HA: 高可靠性分布式存储系统解决方案的历史演进
- js避免onmouseover onmouseout多次触发
- 随机产生0,1(模拟抛硬币)
- 常见的JDBC连接池
- 多线程编程之自旋锁,读写锁
- Keen,China Team China Dream