How to build program with Root?


ROOT Version: root_v6.14.06
Platform: Mac OS High Sierra
Compiler: Apple LLVM version 10.0.0 (clang-1000.10.44.4)


This program (G4beamline) has been running for more than a decade using many versions of Root. The previous version used Root 5.34.36.

I found the HowTo “Integrate ROOT into my project with CMake”, and got my program to build with remarkable ease. But the HowTo does not explain how to get Root to actually work. I need to know what parts of Root need to be copied into my application directory so I can include them in distributions.

As long as my program does not call any Root function, it runs correctly, including 109 regression tests that don’t use Root.

The first call to a Root function crashes – it is looking for stuff from $ROOTSYS/etc in the application directory (or in $PWD which happens to be the same). So I symbolically linked $ROOTSYS/{etc,include}, and linked a bunch of .pcm files into my lib directory. That got past the error messages; now it just crashes and I haven’t a clue what to do. Stack trace below.

The only parts of Root that are used directly are TFile, TDirectory, and TNtuple. In CMakeLists.txt I used “find_package(ROOT REQUIRED COMPONENTS RIO)”.

Note that ROOTSYS still points to the Root installation ($HOME/root_v6.14.06).
So why can’t it find stuff?
What do I have to do to make it work?
Is there now a global initialization function needed before other calls to Root?

Stack Trace for signal 11:
0 0x10eeafa75 g4bl BLSignal::sighandler(int) + 181
1 0x7fff688dff5a libsystem_platform.dylib _sigtramp + 26
2 0x0 ??? ??? + 0
3 0x11491f670 libCling.so TCling::EnableAutoLoading() + 32
4 0x110e26a74 libCore.so TROOT::InitInterpreter() + 628
5 0x110e267f1 libCore.so ROOT::Internal::GetROOT2() + 33
6 0x1112b17be libRIO.so TFile::TFile(char const*, char const*, char const*, int) + 222
7 0x10eeabe13 g4bl RootNTuple::RootNTuple(G4String, G4String, G4String) + 1699
… this last and all following lines are G4beamline code. That function is creating a TFile, TDirectory, and TNtuple for output.

Hi,
Can you try a source $ROOTSYS/bin/thisroot.sh before running?

Also what does LD_LIBRARY_PATH contain?

LD_LIBRARY_PATH and DYLD_LIBARY_PATH are both unset.

“source $ROOTSYS/bin/thisroot.sh” fixed the problem.

Now I have to figure out why, and determine how much of Root I need to copy into my distribution. (Copying it all would quadruple the size of the distribution.)

cling tries to dlopen some libraries at runtime – you can check which with a debugger.
In principle, as long as those libraries’ directories are in the LD_LIBRARY_PATH, cling will find them.

I will close this as solved since the titular issue is solved. Feel free to start a new thread if something different comes up, or comment below for a follow-up on this question.

Cheers,
Enrico

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