我有一个使用log4cxx、boost等库的项目,这些库的头文件会生成很多(重复的)警告。有没有办法抑制来自库包含(即#include )或某些路径的包含的警告?我想像往常一样在项目代码中使用-Wall和/或-Wextra,而不会模糊相关信息。我目前在make输出上使用grep,但我想要更好的输出。
发布于 2009-12-14 20:12:10
您可以尝试使用-isystem
而不是-I
来包含库头。这将使它们成为“系统头”,并且GCC不会为它们报告警告。
发布于 2014-10-10 18:54:47
对于那些使用CMake的用户,您可以修改您的include_directories
指令,使其包含symbol SYSTEM
,该符号将禁止针对此类标头的警告。
include_directories(SYSTEM "${LIB_DIR}/Include")
^^^^^^
发布于 2012-11-21 19:46:41
您可以使用编译指示。例如:
// save diagnostic state
#pragma GCC diagnostic push
// turn off the specific warning. Can also use "-Wall"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/lexical_cast.hpp>
// turn the warnings back on
#pragma GCC diagnostic pop
https://stackoverflow.com/questions/1867065
复制相似问题