我在Ubuntu 16.04,GCC 5.4。
根据here,可以通过将其视为系统标头来禁用外部标头的警告。但是,当我使用VTK时,我遇到了一个警告,我无法禁用。以下是重现它的最小代码
#include "vtkVersion.h"
int main(){
return 0;
}
使用g++ main.cpp -isystem /usr/include/vtk-5.10/
返回警告消息
In file included from /usr/include/c++/5/backward/strstream:50:0,
from /usr/include/vtk-5.10/vtkIOStream.h:108,
from /usr/include/vtk-5.10/vtkSystemIncludes.h:40,
from /usr/include/vtk-5.10/vtkIndent.h:24,
from /usr/include/vtk-5.10/vtkObjectBase.h:43,
from /usr/include/vtk-5.10/vtkObject.h:41,
from /usr/include/vtk-5.10/vtkVersion.h:29,
from Example.cpp:3:
/usr/include/c++/5/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]
#warning \
^
如果未安装VTK,您可以使用sudo apt-get install libvtk5-dev
为什么会出现警告?在我的代码中,我有非常严格的编译器标志,我将警告视为错误。但是,并非所有外部库都使用如此严格的编译器标志进行编码,我能够使用-isystem
标志包含外部标头,但VTK给我带来了问题。我丑陋的解决方法是在我自己的编译器标志中添加-Wno-deprecated
来传递它,但显然这不是正确的方法。什么是解决这个问题的最佳方法?