in a standalone CMake project with ROOT integration, I get several of this type of compilation warnings from “metacling” for some derived classes that I create:
Warning in <MyClass>: The data members of MyClass will not be stored, because it inherits from TObject but does not have its own ClassDef.
I believe it happens when calling ROOT_GENERATE_DICTIONARY(…) CMake macro.
I would prefer not to define a ClassDef for these classes. Is there an empty ‘ClassDef’ macro or compilation flag / verbosity level to disable this warning explicitly, so that I do not get the command line filled with it, which makes it harder to find the real warnings?
If you class inherits from TObject AND you do not use a ClassDef then the data in those classes will not be saved (because the system relies on the overload of functions implemented in the linkdef, eg, IsA and `Streamer).
I.e. It is a REAL warning and actually in almost all cases an error.
Why do you prefer to not define a ClassDef? What is the advantage for you?
It is a GUI window, thus I do not want to save it or stream it.
class MainWindow : public TGMainFrame
In principle, I would have no problem of adding the ClassDef even if I do not need it. But the problem is that, if I add it, I am not able to use forward declaration in my header.
I use now:
Without ClassDef, all works fine except for the metacling warning.
With the ClassDef, that fails to compile, with the error:
Error in <CheckDefinition>: Missing definition for class TGTab, please #include its header in the header of MainWindow
In file included from input_line_8:3:
In file included from MainWindow.hpp:9:
/opt/root_bld/include/TGFrame.h:34:7: error: incomplete type 'TGTextButton' where a complete type is required
Thus, I prefer to keep my headers cleaner without extra includes and ClassDefs.
Well having a LinkDef let you control more carefully what the dictionary does and would give you an opportunity to suppress the warnings.
Alternatively you could try a relatively new alternative (so you mileage may vary) and remove the dictionary generation altogether and add a ClassDefInline macro (instead of the ClassDef macro).
If it works in you case, it will simply your build while still letting you use forward declaration.
The only downside is that I have to add in my main.cpp file all the paths that are in my CMakeLists, hard-coding them by hand, as the files I want to #include depend on them:
(which I did not need to do before when I generated the explicit dictionaries as CMake was taking care of all of it)
gInterpreter->Declare("#include \"MainWindow.hpp\"");//MainWindow.hpp includes headers that are located in the places above
Or is there a more automated way of passing to TInterpreter the same include-paths as used in the CMakeLists.txt ?