用google protobuf 生成的.h 和.cpp放到工程目录下,并添加好头文件目录和lib目录,在main.cpp里面添加
#pragma comment(lib,"libprotobuf.lib")//链接库文件
#pragma comment(lib,"libprotoc.lib")//链接库文件
之后,会发现编译不过,具体就是
d:\program files (x86)\microsoft visual studio 12.0\vc\include\xutility(2132): 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'
然后从网上找到解决方案在消息头文件中添加
#ifndef _ITERATOR_DEBUG_LEVEL
#define _ITERATOR_DEBUG_LEVEL 0
#else
#undef _ITERATOR_DEBUG_LEVEL
#define _ITERATOR_DEBUG_LEVEL 0
#endif
后来发现还是有问题。
libprotobuf.lib(common.obj) : error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '2' doesn't match value '0' in addressbook.pb.obj
lib里面的obj的_ITERATOR_DEBUG_LEVEL 和消息obj的_ITERATOR_DEBUG

在使用google protobuf时,将生成的头文件和源文件加入VS2013工程后,编译遇到C4996警告以及LNK2038错误,涉及 '_ITERATOR_DEBUG_LEVEL' 值不匹配问题。为消除警告,尝试在消息头文件中定义 Iterator_Debug_Level 为0,但仍然存在问题。最终通过修改lib工程的Preprocessor Definitions,设置 Iterator_Debug_Level 为0,成功解决了编译错误。
最低0.47元/天 解锁文章
2552

被折叠的 条评论
为什么被折叠?



