Defined_in LinkDef directive does not create STL dicts

Hi all,

I have set up an analysis package where people frequently add to the set of classes for which we want to write dictionaries. Rather than have multiple people edit the LinkDef.h file directly, I have set up my Makefile to grep through the header files for the ClassDef phrase, then make use of the defined_in directive via

	@$(foreach d,$^,echo "#pragma link C++ defined_in \"$(d)\";" >>$@;) 

This works great for the classes themselves, but there is a problem. Many of the high-level classes have STL containers of other classes as members. Other member functions that interact with these containers work fine, but if the container itself is exposed, I can’t interact with them via the interpreter. Rootcint is not generating the dictionaries for these classes, even though I have the “link C++ nestedclasses” directive as well.

I’ve made a simple example to test the problem: a class MyClass, which contains a std::vector named “vec”. I compile with

rootcint -f -c `root-config --cflags` -p MySubClass.h MyClass.h LinkDef.h
g++ -Wall -fPIC -shared -o `root-config --libs --cflags`

Then run:

root [0] .L
root [1] MyClass mc
root [2] mc.vec.size()
Error: Can't call vector<MySubClass,allocator<MySubClass> >::size() in current scope (tmpfile):1:
Possible candidates are...
(in vector<MySubClass,allocator<MySubClass> >)
Error: Symbol mc is not defined in current scope  (tmpfile):1:
Error: Failed to evaluate mc.vec
Error: Failed to evaluate mc.vec.size()
*** Interpreter error recovered ***

Everything works fine if I add an explicit “#pragma link C++ class std::vector+;” to the LinkDef.h file, but this defeats my automagic building.

So, is this a bug? Or is this the intended behavior of the defined_in directive? If so, the description at should perhaps be updated to be more explicit. If this is intended behavior, any straightforward workarounds to the problem?

Many thanks,
LinkDef.h (239 Bytes)
MyClass.h (318 Bytes)
MySubClass.h (278 Bytes)

In your “LinkDef.h” file, use either: #pragma link C++ defined_in "./MySubClass.h"; #pragma link C++ class std::vector<MySubClass>+; #pragma link C++ defined_in "./MyClass.h"; or: #pragma link C++ class MySubClass+; #pragma link C++ class std::vector<MySubClass>+; #pragma link C++ class MyClass+; and then: rootcint -f -c -p MySubClass.h MyClass.h LinkDef.h `root-config --cxx --cflags` -fPIC -shared -o

Thank you Wile, this does indeed get the dictionary to generate, but it doesn’t solve my original problem, which is to generate all the dictionaries knowing only the names of the header files, without needing to know their contents.