0

I am on Ubuntu 16.04, GCC 5.4.

According to here one can disable warnings from external headers by treating them as system headers. However, when I am using VTK I came across a warning that I am unable to disable. Below is the minimum code to reproduce it

#include "vtkVersion.h"

int main(){
 return 0;
}

Compile it with g++ main.cpp -isystem /usr/include/vtk-5.10/ return warning message

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 \
  ^

If VTK is not installed you can simply install it with sudo apt-get install libvtk5-dev

Why does the warnings appeared? In my code I have very strict compiler flags and I treat warnings as errors. However, not all external libraries are coded with such strict compiler flags, I am able to get away with including the external headers with the -isystem flag but VTK is giving me problems. My ugly workaround is adding -Wno-deprecated in my own compiler flags to get pass it but obviously this is not the right way to do it. What's the best way to solve this?

Community
  • 1
  • 1
user3667089
  • 2,996
  • 5
  • 30
  • 56
  • Does it still compile without the `-isystem` part? What about if you change `""` to `<>` in the `#include`? – Nir Friedman Mar 02 '17 at 00:14
  • @NirFriedman Makes no difference with `<>`, without `-isystem` it won't be able to find where `vtkVersion.h` is. – user3667089 Mar 02 '17 at 00:16
  • You should be using `` (or rather, the vtk library should). It's possible that giving -std=c++03 or similar will solve this. I'm not entirely sure what version of C++ that gcc defaults to these days - a while back you had to actually ask to get C++11, but I believe a recent (as in the past year or two) change has moved that along to be either C++11 or C++14 as the default, and you have to request the OLD version instead. – Mats Petersson Mar 02 '17 at 00:26
  • @MatsPetersson adding `-std=c++03` is no better than adding `-Wno-deprecated`, I will try to file an issue with VTK but no guarantee they will fix it. Still confused why `-isystem` doesn't work though. – user3667089 Mar 02 '17 at 00:29
  • @user3667089 I suggested dropping the -isystem because I thought maybe it's getting the path somewhere else (and possibly the library is symlinked to a generic library dir). This is definitely a weird one. I would try testing against clang. – Nir Friedman Mar 02 '17 at 01:06
  • The best way would be to upgrade vtk. Version 7.1 has been released a few months ago... – mirni Mar 02 '17 at 11:34
  • @mirni Building VTK 7.1 from source solved the problem. I am still curious why `-isystem` doesn't work. – user3667089 Mar 02 '17 at 17:23
  • I suspect that it is because the warning is generated using the preprocessor #warning directive, i.e. it is forced from code, and not by compiler (such as -Wunused-value or whatever else the compiler generates). I don't have any evidence for this hypothesis though... – mirni Mar 03 '17 at 17:32

0 Answers0