You are here

Interacting with Shared Libraries: rootcling

Not only can cling interpret C++, it can also call functions inside libraries! But it needs a bit of help: the dictionary. These dictionaries are also needed to write a class to a ROOT file.


A dictionary ("reflection database") contains information about the types and functions that are available in a library.

ROOT's dictionary consists of a source file which contains the type information needed by cling and ROOT's I/O subsystem. This source file needs to be generated from the library's headers and then compiled, linked and loaded - only then does cling and ROOT know what's inside a library.

Using ACLiC to generate dictionaries

ROOT can automatically generate dictionaries for you, given a header file. For that just run

.L MyHeader.h+
As explained in more details in the cling prompt web page, the "+" at the end (ACLiC) invokes the dictionary generator and all the rest.


Generating a dictionary by hand

ROOT's dictionary generator is called rootcling. You invoke it as
rootcling -f DictOutput.cxx -c OPTIONS Header1.h Header2.h ... Linkdef.h
Let's look at the different parts:
  • DictOutput.cxx specifies the output file that will contain the dictionary. It will be accompanied by a header file
  • OPTIONS can be simply skipped. Or it can be
    • -Isomething //to add an include path, i.e. to help rootcling find files included in Header1.h, Header2.h, etc.
    • -DSOMETHING //will define a preprocessor macro which is sometimes needed to parse header file.
  • Header1.h Header2.h... are the headers that rootcling will read and extract the type information from.
  • Linkdef.h is the magic file that steers rootcling; it's worth its own page!


Embedding the rootcling call into a GNU Makefile


.L MyCode.C+
to compile and run code is the simplest option If you really need to use a Makefile, here is a rule for generating a dictionary. It will create a new source file which you should compile and like like all the other sources in your library. Of course you will need to add the include path for ROOT, and you might have to link against ROOT's libraries libCore.

This rule will generate the rootcling dictionary for the headers $(HEADERS) and a library containing the dictionary and the compiled $(SOURCES):

MyDict.cxx: $(HEADERS) Linkdef.h
[TAB]     rootcling -f $@ -c $(CXXFLAGS) -p $^ MyDict.cxx $(SOURCES)
[TAB]     g++ -shared -o$@ `root-config --ldflags` $(CXXFLAGS) -I$(ROOTSYS)/include $^