Loading libraries within macro

I have a very basic question. Given the macro main.C (see end of message for all files mentioned), if I do

root main.C

I get the error list error.log, as if the libExRootAnalysis.so had not been loaded at all.

If instead I comment out lines 5-6 of main.C and do

root init_ROOT_session.C
.x main.C

where init_ROOT_session.C is a separate script just containing lines 5-6 of main.C, then the script is executed correctly.

What’s wrong with putting lines 5-6 directly inside main.C ?

Thank you,
Diego

PS: all mentioned files are retrievable at this link

With Cling, we parse the script before executing its content. This means that if the library load is done inside main.C then the symbol ExRootTreeReader is seen (and complained about) before the library is even attempted to be loaded.

You have 3 additional work around (in addition to the extra script):

(a) transform main.C from an unnamed macro to a named macro (i.e. you need to give a name to the function, usually the same as the file name) and add at the beginning of the file (so that it is handled at parsing time):

R__LOAD_LIBRARY(libExRootAnalysis);
R__LOAD_LIBRARY(libPhysics);

(b) Generate a rootmap file for your library and add its location/directory to the LD_LIBRARY_PATH to enable auto-loading.

( c ) Use the tip of the main development branch or the soon to be released v6.24/00 and just add the location/directory of the library to the LD_LIBRARY_PATH to enable the new library auto-loading mechanism.

1 Like

I finally opted for a separate script for all the required libraries, libscript.C in the following.

Now, libscript.C looks as follows:

{
gSystem->Load(“libPhysics”);
gROOT->ProcessLine("#include “RequiredLibs/lester_mt2_bisect_and_maos.h”");
gROOT->ProcessLine("#include “~/MyFolders/PhysicsCodes/YAM2/src/yam2.h”");
gROOT->ProcessLine("#include “~/MyFolders/PhysicsCodes/YAM2/src/lhef_helper.h”");
}

The last of the headers loaded above (lhef_helper.h) starts itself with the following headers

#include // std::array
#include // std::optional
#include // std::ostream
#include // std::set
#include // std::pair
#include // std::vector
#include “HepMC3/LHEF.h” // LHEF::HEPEUP

As a result, if I do
root libscript.C
the root prompt yields the following error:

/lhef_helper.h:16:10: fatal error: ‘HepMC3/LHEF.h’ file not found
#include “HepMC3/LHEF.h” // LHEF::HEPEUP

Before running root, I redefined all of ROOTSYS, PATH, LD_LIBRARY_PATH, DYLD_LIBRARY_PATH so that they include . I didn’t know/remember which one was the right one, so I tried with all of them. Apparently, none is the right one.

How should I instruct the root prompt to look into ?

More generally, what are the paths that ROOT looks into, in case of

#include <headerfile.h>

and in case of

#include “headerfile.h”

and how can one add more such paths?

In your libscript.C add:

gInterpreter->AddIncludePath("/path/to/include"); // where "HepMC3/LHEF.h" resides

1 Like

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