Problem with forward declarations and cint dictionary

Hi,

in my class TH5Dataset, I need to forward-declare the class TH5MainFrame. (I cannot include the header file in TH5Dataset.h, because TH5MainFrame.h already includes TH5Dataset.h). When I create and compile the dictionary classes, I get the following error:

g++ -I/include/hdf5/hdf5-1.6.5/hdf5/include -I/include/svnwork/H5Root/…/H5Part/src/ -g -Wall -fPIC -pthread -m64 -I/opt/root/5.16.00/include/root -c TH5Dataset.cc
g++ -I/include/hdf5/hdf5-1.6.5/hdf5/include -I/include/svnwork/H5Root/…/H5Part/src/ -g -Wall -fPIC -pthread -m64 -I/opt/root/5.16.00/include/root -c TH5DatasetDict.cc
/opt/root/5.16.00/include/root/TBuffer.h: In function TBuffer& operator>>(TBuffer&, Tmpl*&) [with Tmpl = TH5MainFrame]': TH5DatasetDict.cc:162: instantiated from here /opt/root/5.16.00/include/root/TBuffer.h:339: error: invalid use of undefined typestruct TH5MainFrame’
TH5Dataset.h:31: error: forward declaration of struct TH5MainFrame' /opt/root/5.16.00/include/root/TBuffer.h: In functionTBuffer& operator<<(TBuffer&, const Tmpl*) [with Tmpl = TH5MainFrame]’:
TH5DatasetDict.cc:215: instantiated from here
/opt/root/5.16.00/include/root/TBuffer.h:346: error: invalid use of undefined type struct TH5MainFrame' TH5Dataset.h:31: error: forward declaration ofstruct TH5MainFrame’
make: *** [TH5DatasetDict.o] Error 1

Somehow, TBuffer does not like my forward declaration. What am I doing wrong? (Sorry if this is a known/trivial issue…)

Many thanks,

Thomas

Hi,

it does like your forward declaration, it’s just not enough :slight_smile: When generating the I/O code for TH5Dataset it also needs to do I/O for the TH5MainFrame member. But it cannot, because it’s not defined. The solution: either simply add TH5MainFrame.h to the rootcint call, or generate the dictionary for TH5MainFrame and TH5Dataset in one go (i.e. in one Linkdef.h).

Cheers, Axel.

Thanks for the clarification, Axel! Hmm… it looks like I need you to be (even) more specific:
I try solution 1 by putting
@rootcint -f TH5DatasetDict.cc -c TH5Dataset.h TH5MainFrame.h
@rootcint -f TH5MainFrameDict.cc -c TH5MainFrame.h
in my GNUmakefile (i.e. just adding TH5MainFrame.h to the rootcint call). This gives me a multiple declaration error:

TH5DatasetDict.o(.text+0x608): In function TH5MainFrame::Dictionary()': /include/svnwork/H5Root/TH5DatasetDict.cc:127: multiple definition ofTH5MainFrame::Dictionary()'
TH5MainFrameDict.o(.text+0x3c8):/include/svnwork/H5Root/TH5MainFrameDict.cc:94: first defined here
TH5DatasetDict.o(.text+0x372): In function ROOT::GenerateInitInstance(TH5MainFrame const*)': /include/svnwork/H5Root/TH5DatasetDict.cc:64: multiple definition ofROOT::GenerateInitInstance(TH5MainFrame const*)'
etc.

I am not sure about solution 2 either. Do you mean changing the LinkDef.h file to something like this:
#ifdef MAKECINT
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class TH5MainFrame TH5Dataset;

instead of separate
#pragma link C++ class TH5MainFrame;
#pragma link C++ class TH5Dataset;
??

That didn’t help either.
Sorry for being a bit thick on this…

Thomas

Hi,

from what you sent I don’t think you pass LinkDef.h to rootcint. So do the following:

#ifdef MAKECINT
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclasses;
#pragma link C++ class TH5MainFrame+;
#pragma link C++ class TH5Dataset+;
#endif

into LinkDef.h, and then run
rootcint -f TH5DatasetDict.cc -c TH5Dataset.h TH5MainFrame.h LinkDef.h

That should give you a combined dictionary for both classes.

Cheers, Axel.

I got it now - thanks for your help.
What a great forum this is!!

Thomas

Glad I could help. After all, we live of bread, water, and happy users! :slight_smile:
Cheers, Axel.