vs2013编译google protobuf生成的消息文件错误。

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值