3 回答

TA贡献1799条经验 获得超6个赞
对于使用CMake的用户,您可以修改include_directories指令以包括SYSTEM禁止显示此类标题警告的符号。
include_directories(SYSTEM "${LIB_DIR}/Include")
^^^^^^

TA贡献1796条经验 获得超7个赞
您可以使用编译指示。例如:
// 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

TA贡献1998条经验 获得超6个赞
#pragma是对编译器的指令。您可以在#include之前设置某些内容,并在之后将其禁用。
您也可以在命令行中执行此操作。
另一个GCC页面专门关于禁用警告。
我会选择在源代码中使用#pragma,然后提供您为什么禁用警告的 合理原因(作为注释)。这意味着要对头文件进行推理。
GCC通过对警告类型进行分类来解决此问题。您可以将它们分类为警告或被忽略。先前链接的文章将向您显示可能禁用了哪些警告。
注意:您也可以使用属性按摩源代码以防止某些警告。但是,这使您与GCC紧密相关。
注意2:GCC还使用了Microsoft编译器中使用的pop / push接口 -Microsoft通过此接口禁用警告。我建议您对此进行进一步调查,因为我什至不知道是否有可能。
添加回答
举报