Faster way to Load Libraries and Precompile .cpp files?

Hi everyone,

In order for my macros to run properly on ROOT, I have to load a library and compile a .cpp file (that defines class functions of a .hpp header). I don’t like to launch ROOT and load both manually everytime with

.L /path/to/lib/
.L /path/to/file.cpp+

so what I have done instead is define an alias in my .bashrc file, which goes like:

alias roott='root -l -L /path/to/lib/ -L ~/path/to/file.cpp+'

This all works really well and I am generally happy. However, whenever I launch roott, it takes (and reasonably so) a while to compile (~15 seconds) and sometimes it becomes quite annoying, particularly when I am exiting ROOT to make a small amend and come back in. Is there any workaround that will make things a bit faster?

Thank you,


_ROOT Version: 6.24/06
_Platform: Centos08
_Compiler: g++ (GCC) 11.1.0

You can also put the two commands in your rootlogon.C file.
file.cpp+ is some C++ code. .L /path/to/file.cpp+ will compile it.
May be compile it once and load the .so as you do for

Thank you a lot for the reply,

The .L inside the rootlogon.C does not seem to work. However,


seems to be working flawlessly. This however does not resolve the compilation of the file.cpp. I tried:


and I got:

Error in <TUnixSystem::FindDynamicLibrary>: /home/andreas/ROOTScripts/Classes/Cluster.cpp+[.so | .dll | .dylib | .sl | .dl | .a] does not exist in /cvmfs/

Changing it to:


Makes the error disappear, but when I run a file that uses functions defined there, I get an undefined symbol error:

/cvmfs/ symbol lookup error: /path/to/ undefined symbol: _ZN8ClustersC1ESt6vectorIPN6allpix8PixelHitESaIS3_EE

Any possible workaround/solution to this?

Thank you,


Can you compile file.cpp outside ROOT and do:


Instead of loading the .cpp file ?


Yes, this works flawlessly and everything runs as expected. Sorry, I didn’t see it the .so for file.cpp in the first answer. Thank you very much!


1 Like