When I need to gSystem->Load some libraries, I usually have to either pass the full /path/to/the/library.so, or let my LD_LIBRARY_PATH point to it.
This seems to be the case even for system libraries.
Example:
I need to Load libz.so
root [0] gSystem->Load("libz.so")
Error in <TUnixSystem::DynamicPathName>: libz.so does not exist in [... my LD_LIBRARY_PATH ...]
Using ldconfig -p | grep libz.so
I usually check where on the current system the library is installed (sometimes: “/usr/lib”, “/usr/lib/x86_64-linux-gnu”, “/usr/lib64”, “/usr/lib/i386-linux-gnu”) and do:
root [1] gSystem->Load("/usr/lib/libz.so")
(int)0
However, if I want any of my coworkers to use this script. They will have to do edit the file, in order to use it. Or they have to let their LD_LIBRARY_PATH point to the location of their libz.so, i.e. let the LD_LIBRARY_PATH point to one of the default locations. This sounds a little wierd to me.
So I wonder if there is any way to tell the root dynamic library loader (is this the correct term?) to not only search in the LD_LIBRARY_PATH for dynamic libs to load, but also in the default system folders first.
You know, those folders one gets using: ldconfig -v 2>/dev/null | grep -v ^$'\t'
for example.
Thank you for your time.
Dominik
Hi Dominik,
in your $HOME/.rootrc you can use a resource e.g like this.
See also the system wide defaults in: $ROOTSYS/etc/system.rootrc
Cheers
Otto
Hi Otto,
thank you for your quick reply. However the answer, if I correctly understand it, does not quite solve my problem. Maybe I didn’t express myself very good, so I try again:
I am writing a custom library for my experiment, I would like to call from within ROOT (PyROOT actually, but that doesn’t matter here). Within that code I #include <zlib.h> and in order to build that library I usually do:
root [0] gSystem->Load("/usr/lib/libz.so")
(int)0
root [1] .L my_library.h+
Info in <TUnixSystem::ACLiC>: creating shared library /path/to/my_library_h.so
Now in order to deploy this libary on other persons machines I have to provide a kind of setup.C, so they just have to execute that setup.C in order to build the libs, before they can use them. However it turns out that I need to know the /path/to/other/persons/libz.so in order to write the setup.C for them.
On the other hand, if I want to use my_libary.h without root, all I need to do, is to tell gcc to link agains the libz, using the -lz option, since the linker and loader both already know where to search for the libz.so, just for ROOT I have to manually set the correct path.
My question is:
Is there a way to tell the root dynamic library loader not only to search inside the LD_LIBRARY_PATH and similar locations, given by the user, but also search inside these so called “default locations for shared libraries on *nix systems”.
Try: root [0] gSystem->AddLinkedLibs("-lz"); // ACLiC's linker will take care of it
root [1] std::cout << gSystem->GetLinkedLibs() << std::endl; // just for fun
root [2] .L my_library.h+
Awesome!
Thank you very much!