Using user defined function in cling

Is it possible to use a user defined function, not a class, interactively in cling? I have yet to figure out how to do this. I can compile a dictionary with a function, and I understand I need a rootmap file to inform cling of symbols and shared libraries where they reside. But when I am trying to implement a function in the LinkDef I use the following pragma:

#pragma link C++ function double func(double);

and rootcling does not generate any output the rootmap file. If I do this whole routine but instead define func as a class instead of a function, then there is no problem; the rootmap file contains the proper entries for the class and I can use the class interactively.

Is the only way to use user defined content interactively in cling through classes? Would someone please provide a simple working example of source code and Makefile or commands to make this work?

By the way in ROOT 5.34 rlibmap would not generate output for the function pragma either, but if I manually put an entry in the rootmap file like


CINT would allow me to access the function interactively anyway. Now if I try something similar using ROOT 6 and cling, I can see the function in cling (tab autocompletes the function name on the command line), but will not actually run the function. I get an error.


@vvassilev explained me that it is a missing feature in ROOT6. Probably he can explain you a bit more here…



Automatic loading of functions is not supported in ROOT6 yet. This only works with the experimental C++ modules feature (if you build with -Druntime_cxxmodules=On).

Best, Vassil

Another common workaround is to put the function into a class / namespace, and create an autoload rootmap entry for that class / namespace. But indeed, as @vvassilev is pointing out, modules are the way we’ll solve this! (And they are way less experimental than Vassil’s answer makes it sound - we are considering turning them on by default for Linux for ROOT v6.20!)

Thanks for the information.

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