I need to dynamically link to a number of .so
shared libraries from R. R can only do this one at a time using the dyn.load
function, which takes the file path of the shared object. However, if the shared library that I load has dependencies on another shared library that I haven't already loaded, then the linking will fail.
Thus, I need to obtain a topological sort of the dependencies of a list of shared libraries so I can link them in the correct order. I realise that I can extract this information by running ldd
on each shared library and parsing the results, but I wonder if there is an existing utility that can take a list of shared libraries and topologically sort them for me, to give me an easy load order.
I have looked into the lorder
command, but I think this is only designed for static libraries (?), and also ar -ts
, but I think this has the same problem. If I am wrong, feel free to correct me.
Is there any common Linux utility that will give me a linking order for these shared objects? I'm on CentOS 7 by the way.
RTLD_LAZY
mentioned inman dlopen
? (I don't know if that is sufficient though).dlopen
, but neither theRTLD_LAZY
variable, nor thenow = FALSE
argument to the function seem to matter.