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!
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”).
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