.so loader

Is it possible to execute code BEFORE a shared object gets automatically loaded.

The problem is that we can be working in multiple projects as the same time ( different versions). Each have their own set of shared object and binaries located in their private directory. The problem with this is that the path for the shared object must be set independantly for each version, this is VERY error prone.

I would like each binaries to set their LD_LIBRARY_PATH dependending on the directory where they are. But for this to work I need to be able to set LD_LIBRARY_PATH before the program loads the DLL.

I’m currently experimenting with attribute constructor, but I get the feeling this will still not be execute before the startup code loads the shared object.


Why not use DT_RPATH? You can embedd the LD_LIBRARY_PATH in the actual binary itself? Use -Wl,–rpath=. Admittedly you can’t then change it, or expand environment variables,
but for your development case it would probably be pretty useful.

I’m afraid this would create confusion. Is it possible for DT_RPATH to contain a directory relative to the position of the executable.