用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