Automatically load in cling

I wrote a few classes inherited from TObject, compiled it with rootcling, created, libMyLib_rdict.pcm, libMyLib.rootmap, and added them to LD_LIBRARY_PATH.

When I get into the root interactive prompt, I can use Tab to show a list of classes defined in my codes. But when I try to run MyNamespace::MyClass a, I got message:

OOT_prompt_2:1:9: error: no member named 'MyClass' in namespace 'MyNamespace'

If I then type .L and run MyNamespace::MyClass a again, everything is fine. It looks like that root can see what’s in my lib, but cannot automatically load it. What could be the cause?

Please let me know if you need more information.

Thanks, Jing


there are 2 solutions for your case in case you do not want to read/write instances of your classes on disk. In case you want to do I/O, only one :wink:

  1. Interactive usage at the prompt and no I/O:
gInterpreter->Declare("#include \"myheader.hxx\"");
  1. Ineractive usage at the prompt, in macros and I/O
    In this case you need to load your library containing your classes automatically and for that you need a rootmap file. You can achieve it like this:
genreflex myheader.h -o myDict.cxx -s mySel.xml --rootmap-lib --rootmap libMyLib.rootmap
g++ -o myDict.cxx myLibMyLibsource.cxx -shared -fPIC `root-config --cflags --libs`


Hi, D,

thank you for the quick reply. I actually already generated libMyLib.rootmap when I generated MyLibDict.cxx using rootcling:

MyLibDict.cxx: $(HEADERS) $(LINKDEF)
        rootcling -f $@ $(CXXFLAGS) -s libMyLib -rmf libMyLib.rootmap $^

I then compile MyLibDict.cxx into What’s in my rootmap file seems reasonable:

{ decls }
namespace MyNamespace {  }

[  ]
# List of selected classes
class MyNamespace::MyClass
header MyClass.h
# List of selected namespaces
namespace MyNamespace

I also checked what’s in my pcm file:

$ root libMyLib_rdict.pcm
[ROOT] __ProtoClasses->ls()
OBJ: TObjArray  TObjArray       An array of objects : 0
 OBJ: TProtoClass       MyNamespace   : 0 at: 0x7fe4208e1db0
 OBJ: TProtoClass       MyNamespace::MyClass        : 0 at: 0x7fe420a332e0

Would rootcling behave differently from genreflex? I don’t have an xml file in my source folder.

By the way, here is what’s in my LinkDef.h:

#pragma link C++ namespace MyNamespace;
#pragma link C++ class MyNamespace::MyClass+;


what you did is right: genreflex and rootcling are equivalent.
Is the rootmap, the library and the root pcm in the LD_LIBRARY_PATH?


They are in the same folder. I double checked my LD_LIBRARY_PATH. The folder is included. Another proof is that my ROOT prompt responds to my TAB key to complete my typing of the class and namespace names (even though it cannot run it). Attached please find a simplified package to demonstrate my problem.smpl.tar.gz (6.8 KB). Simply type make to generate lib, rootmap and pcm files.

I remember in ROOT5, rootmap file lists dependence between libs. But in ROOT6 rootmap file only contains information about my own lib. Could you please explain the reason of this difference?

Hi Jung,

what happens if you type


does this return a non-null ptr? Are there any error messages?


It returns a nullptr. No error message.


thanks. I just noticed a problem in your rootcling invocation. You use:

rootcling -f $@ $(CXXFLAGS) -s libMyLib -rmf libMyLib.rootmap

You should use

rootcling -f $@ $(CXXFLAGS) -rml libMyLib -rmf libMyLib.rootmap


Hi, D,

You spotted it. That is indeed the problem. Once I switched from -s to -rml with other things the same, I could have the lib automatically loaded.

However, without -s libMyLib the name of the pcm file becomes MyLib_rdict.pcm instead of libMyLib_rdict.pcm. I guess the name does not matter much, but I end up with using both -s and -rml so that I can have the pcm file name consistent with other ROOT libs and still be able to have my own lib automatically loaded.

Thanks, Jing

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.