Shared Library Autoload

Hello ROOTers,

I am running into an issue, whereby the library “autoload” feature keeps loading a version of a library that is different from the one I want.

Here is a bit more about the situation:

I am working on a server that is shared between all members of my research group (myself and a number of students). Some time ago, I downloaded and complied a code base (which uses ROOT) into a shared library (let’s call it I want everyone who uses the server to have easy access to the classes declared in this library from within a ROOT session. In order do this, I copied the .so file into /opt/lib (for better or worse). Until now this works well. Any user can log in, open ROOT, declare an instance of some class that is part of the library, and the library auto-loads.

Now here is where I start to have problems. I needed to make a separate version of this library (for my own use), which has some changes to the header files. I do this and leave in a directory that is local to my user account (call it /path/to/my/lib). I add this directory to my LD_LIBRARY_PATH (prepending it, so it should take priority). All good so far - for example I can create compiled code with g++ linking to this library with no problems.

The problem happens when I start ROOT and try to create an instance of some class in libXYZ. ROOT always seems to autoload the version of libXYZ in /opt/lib, so that I cannot ever get access to my new class in a ROOT session.

Is there any way aroud this? Basically, I want to disable the auto-loading of the library in /opt/lib and instead load (either manually or automatically) the version in /path/to/my/lib).

Many thanks for your help.

ROOT Version: 6.26/04
Platform: Ubuntu 22.04
Compiler: Not Provided

Hi Greg,

Isn’t this due to the fact that the linker looks before in the system directory and then to the LD_LIBRARY_PATH?

If I am understanding the issue correctly (and please correct me if I am wrong!), there could be several ways to fix it, depending what is triggering the autoload, i.e. undefined symbol or I/O.
Some options:

  1. Change the name to he lib or make a symbolic link to it and change the name of it in the rootmap file ROOT reads to be able to autoload
  2. Load manually the library with gSystem->Load("libMylib") (works if this is not an undefined symbol triggering the load, it is executed at runtime) or R__LOAD_LIBRARY(libMylib) (works for undefined symbol, executed at parse time)
  3. Use rpath when you build your lib (this is the heaviest solution)

I hope at least one option unblocks you. In case of issues, do not hesitate to come back with questions.


Hi Danilo,

Thank you for the quick reply. As it turns out, the issue is not a ROOT one at all, but rather related to how I compile my library. At compile time, I was pulling in system header files from /opt/include rather than the local ones that I want!

I discovered this by realizing that the code in the *.cxx files tracks with the expected library when trying your various helpful suggestions.

I did want to point out one thing, related to this statement:

Isn’t this due to the fact that the linker looks before in the system directory and then to the LD_LIBRARY_PATH?

This is true if the new path is appended to $LD_LIBRARY_PATH, i.e.

export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/my/new/path

However, if you prepend instead:

export LD_LIBRARY_PATH=/my/new/path:${LD_LIBRARY_PATH}

then /my/new/path takes precedence over the system directories.


Dear Greg,

Thanks for reporting back and for the complement of information.
Glad to hear the setup now works!


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