对于一个简单的 proto 文件:
消息人{ 必需的 int32 id = 1; 所需的字符串名称 = 2; 可选字符串电子邮件 = 3; }
它由 protoc.exe 编译,结果用于一个同样简单的测试项目,除了包含 protoc 生成的文件之外,它基本上什么都不做。
我正在使用 msvc10 构建测试项目(x64),然后它给了我很多警告:
警告 1 警告 C4244: 'return' : 从 '__int64' 转换为 'int',可能丢失数据 D:\Work\protobuf-trunk\src\google\protobuf\descriptor.h 1441 1 testProtobuf ... 警告 11 警告 C4267:'argument':从 'size_t' 转换为 'int',可能丢失数据 D:\Work\protobuf-trunk\src\google\protobuf\unknown_field_set.h 142 1 testProtobuf 警告 12 警告 C4267:'return':从 'size_t' 转换为 'int',可能丢失数据 D:\Work\protobuf-trunk\src\google\protobuf\unknown_field_set.h 237 1 testProtobuf ... 警告 14 警告 C4244:'=':从 '__int64' 转换为 'int',可能丢失数据 D:\Work\protobuf-trunk\src\google\protobuf\io\coded_stream.h 902 1 testProtobuf 警告 15 警告 C4244:'return':从 '__int64' 转换为 'int',可能丢失数据 D:\Work\protobuf-trunk\src\google\protobuf\io\coded_stream.h 1078 1 testProtobuf 警告 16 警告 C4267:'argument':从 'size_t' 转换为 'google::protobuf::uint32',可能丢失数据 D:\Work\protobuf-trunk\src\google\protobuf\wire_format_lite_inl.h 663 1 testProtobuf ... 警告 19 警告 C4267:'return':从 'size_t' 转换为 'int',可能丢失数据 D:\Work\protobuf-trunk\src\google\protobuf\wire_format_lite_inl.h 739 1 testProtobuf 警告 20 警告 C4267:'argument':从 'size_t' 转换为 'google::protobuf::uint32',可能丢失数据 D:\Work\protobuf-trunk\src\google\protobuf\wire_format_lite_inl.h 742 1 testProtobuf 警告 21 警告 C4267:'return':从 'size_t' 转换为 'int',可能丢失数据 D:\Work\protobuf-trunk\src\google\protobuf\wire_format_lite_inl.h 743 1 testProtobuf 警告 22 警告 C4267:'argument':从 'size_t' 转换为 'int',可能丢失数据 D:\Work\testProtobuf\testProtobuf\person.pb.cc 211 1 testProtobuf ... 警告 28 警告 C4996:'std::_Copy_impl':带有可能不安全参数的函数调用 - 此调用依赖于调用者检查传递的值是否正确。要禁用此警告,请使用 -D_SCL_SECURE_NO_WARNINGS。请参阅有关如何使用 Visual C++ 'Checked Iterators' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility 2239 1 testProtobuf 的文档 警告 29 警告 C4996:'std::_Copy_impl':带有可能不安全参数的函数调用 - 此调用依赖于调用者检查传递的值是否正确。要禁用此警告,请使用 -D_SCL_SECURE_NO_WARNINGS。请参阅有关如何使用 Visual C++ 'Checked Iterators' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xutility 2239 1 testProtobuf 的文档
有什么好的方法来解决所有这些警告吗?任何建议将不胜感激。
附言。libprotobuf 项目本身可以由 msvc10 干净编译而不会发出任何警告。
[编辑 2013/02/20 ]
工作解决方案:
- 为那些 protoc 生成的 .cc 文件设置属性:
配置属性 -> c/c++ -> 高级 -> 禁用特定警告