Loading simple shared library in to ROOT session

I’m looking to make a shared library of some useful functions and load them in to the ROOT environment. No classes involved.

//addition.C int addition(int a,int b) { int result; result = a + b; return result; }

//multiplication.C int multiplication(int a, int b) { int result; result = a * b; return result; }

//header.h int addition(int a,int b); int multiplication(int a,int b);

Now I can make a shared library for use outside of CINT easily enough.

Trying to load this in to ROOT fails, unless you load the header file and let ACLiC compile it.

root [0] .L libarith.so root [1] addition(3,4) Error: Function addition(3,4) is not defined in current scope (tmpfile):1: *** Interpreter error recovered *** root [2] .L header.h+ root [3] addition(3,4) (int)7 root [4]

Is there away around loading/compiling the headers? I’m looking for a one liner to set up a library of functions for interactive use. Or do I need to load each header and/or load each individual source file (.L addition.C, .L multiplication.C, etc.). Thanks!

Credit where credit is due: My example code comes from http://www.thegeekstuff.com/2010/08/ar-command-examples/

You need to generate a CINT dictionary (using rootcint), compile it and link it into your shared library. Otherwise you need the additional “.L header.h+” step (which creates the dictionary “on the fly”).

I did what I could.

$ ls addition.C example.C header.h multiplication.C $ touch Linkdef.h $ rootcint -f arithdict.C -c header.h Linkdef.h $ g++ -shared -I`root-config --incdir --libs` arithdict.C addition.C multiplication.C -o libarith.so $ root root [0] .L libarith.so root [1] addition(3,4) Error: Function addition(3,4) is not defined in current scope (tmpfile):1: *** Interpreter error recovered *** root [2]

What do you think I’m doing wrong?

Hi,

looks like your Linkdef.h file is empty if you just touched it. Try adding the following:

#ifdef __CINT__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma link C++ function addition;
#pragma link C++ function multiplication;

#endif
  • Fons

Thanks. I was misinformed that an empty Linkdef.h was sufficient for simple/classes dictionary generation for running in CINT.