在一个项目中,我使用了VTK(有些旧版本),它在GCC上产生了已弃用的警告:
In file included from <path STL>/backward/strstream:51:0,
from <path VTK>/vtkIOStream.h:112,
from <path VTK>/vtkSystemIncludes.h:40,
from <path VTK>/vtkIndent.h:24,
from <path VTK>/vtkObjectBase.h:43,
from <path VTK>/vtkSmartPointerBase.h:26,
from <path VTK>/vtkSmartPointer.h:23,
from <some file in my project>
<path STL>/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp]
我想取消该警告。到目前为止,我试图在罪魁祸首中使用pragma指令:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wno-deprecated"
#include <vtkSmartPointer.h>
#pragma GCC diagnostic pop
根据对How to suppress several warnings but not all of them coming from libraries?的回答
中的建议但是这不起作用,因为该命令无法识别我的选项:
warning: unknown option after ‘#pragma GCC diagnostic’ kind [-Wpragmas]
#pragma GCC diagnostic ignored "-Wno-deprecated"
我想在此具体说明我禁用的警告类型。不过,也可以欢迎给我一个不太具体的选择的答案。我尝试使用“ -Wall”,但这也不起作用(可以识别但不能抑制)。
使用-Wno-preprecated编译整个项目会禁止显示警告,这是我的后备选项,但我不喜欢使用它。
我的重点是它可以在带有GCC的Linux下工作。我没有管理权限,无法在此处更改VTK版本或GCC(4.8.5)的版本。
答案 0 :(得分:4)
作为评论状态:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated"
#include <vtkSmartPointer.h>
#pragma GCC diagnostic pop
#pragma GCC diagnostic ignored
要忽略指定的警告标志,而不是替代它。
您也可以使用错误消息中报告的标志:[-Wcpp]
:
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcpp"
#include <vtkSmartPointer.h>
#pragma GCC diagnostic pop