Generating dictionary for class inheriting TObject/Interface

I would like to write a class which I can store into a TFile, hence I inherit TNamed and apply ClassDef/ClassImp.

Now, this class inherits another purely abstract inteface a la

class Interface {
public:
void doSomething() = 0;
};

class MyClass : public TNamed, public Interface { };

Now if I compile the class in CINT with

.L MyCkass.cpp+

and try to retrieve it from the file

MyClass* c = (MyClass*)file->Get(“MyClassName”)

I get the following error message:

Processing Test.C…
Warning in TClass::TClass: no dictionary for class Interface is available
Warning in TStreamerInfo::Build:: MyClass: base class Interface has no streamer or dictionary it will not be saved
Fatal in TStreamerInfo::: fv < 30000 violated at line 434 of `meta/src/TStreamerInfo.cxx’
aborting

What is the right way to deal with this?

Thanks a lot,

Philipp

Hi Philipp,

Somehow

did not generate the dictionary for the class Interface.
I suspect that you have a file Interface.h which define the class Interface.

By default ACLiC, i.e

, generate dictionaries only for C++ constructs defined in the file MyCkass.cpp and MyCkass.h and hence do not generate the dictionary for the class Interface if it is not defined in MyCkass.h (even if it is included).

To generate the dictionary for Interface you can either do:

or add the lines

#ifdef __MAKECINT__ #pragma link C++ class Interface+; #endifto MyCkass.h

Cheers,
Philippe.

Hi Philippe,

Thanks, I indeed had solved the problem by generationg the Interface_hpp.so first.

But I like the second solution you suggest a lot better, I’ll try that! (Especially becasue it means I will have only one shared library floating around, right?)

Cheers,

Philipp

Exactly,

Actually you can extend this principle to using a bundle xxx.C file which can #include many other files and you can pick and choice what to expose.

Cheers,
Philippe.

Hi Philippe,

Can I actually somehow put mutiple classes defined and implemented in mulitple *.cpp and *.h files into one shared library? I have a ‘circular dependency’ a la

Mother.h:

class Daugher;

class Mother {
private:
  Daughter* _daughter;
};

Daughter.h:

class Mother;

class Daughter {
private:
Mother* _mother;
};

Is this possible?

What you request is possible AND RECOMMENDED.
One dictionary per class is expensive because there is a constant overhead per dictionary.
Create a LinkDef.h file with a pragma statement for all the classes you want to group in the same shared lib.
In the rootcint command specify the list of all includes defining these classes.
You can see examples in the Root Makefile
or in $ROOTSYS/test/Makefile

Rene

Hi,

Thanks. I actually know how to do this when comiling, I was wondering how to achieve this within a macro doing

.L Mother.C+

and having ‘Daughter’ stuck in the same shared lib. I sthat possible too?

Hi,

The solution is to use an extra file (bundle.C) containing:

// Start of bundle.C #include "Mother.h" #include "Daugher.h" #ifdef __MAKECINT__ #pragma link C++ class Mother+; #pragma link C++ class Daughter+; #endif
and do

Cheers,
Philippe.