无法在Visual C ++中禁用警告

问题描述 投票:1回答:1

我需要从使用外部库ProtocolBuffers的项目目录中禁用所有警告,该库会产生自己的警告。

这些是我收到的151条警告中的一些:

my.pb.cc: warning C4512: 'google::protobuf::FatalException' : assignment operator could not be generated
my.pb.cc: warning C4244: 'initializing' : conversion from '__int64' to 'int', possible loss of data
my.pb.cc: warning C4125: decimal digit terminates octal escape sequence
my.pb.cc: warning C4127: conditional expression is constant
my.pb.cc
xutility(2132): warning 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.

xutility是Visual Studio包含文件的地方。

如果将这些行添加到我的CMakeLists.txt文件中:

# Use a lower warning level threshold for autogenerated files
set(PROTOBUF_FILES_PATH "${CMAKE_CURRENT_BINARY_DIR}/src/*.pb.*")
file(GLOB PROTOBUF_FILES ${PROTOBUF_FILES_PATH})
set_source_files_properties(${PROTOBUF_FILES} PROPERTIES COMPILE_FLAGS /W2)

我禁用了已生成的pb.cc文件中的所有警告,但ProtoBuf内部代码中还剩下15条警告,其类型为:

my.pb.cc
xutility(2132): warning 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.

考虑到我无法修改ProtoBuf本身,如何针对[扩展名-D_SCL_SECURE_NO_WARNINGS的文件,如何禁用这些最后的警告,可能通过添加*.pb.*选项来调整CMakeLists.txt文件?

visual-c++ cmake protocol-buffers compiler-warnings suppress-warnings
1个回答
1
投票

[不了解xutility或Protobuf如何使用它,我建议尝试将set_source_files_properties()调用扩展为包括COMPILE_DEFINITIONS

COMPILE_DEFINITIONS
© www.soinside.com 2019 - 2024. All rights reserved.