I'm maintaining a C-program, that uses Oracle client libraries. The libraries expect the
ORACLE_HOME environment variable to be set, and fail to work without it -- in many cases.
In our situation, the value of the variable is always derived from the location of the shared libraries themselves anyway -- and I'd like to implement setting it from the C-code (using
But, for that, I need to know, from where a particular shared library used by the program was loaded.
ldd, when applied to the executable file, outputs:
libc.so.7 => /lib/libc.so.7 (0x1021000) libmeow.so.1 => /opt/meow/lib/libmeow.so.1
How can the running process itself find out, that
libmeow.so, which it is using, is loaded from
The answer needn't be universally-portable -- something, that'd work for just Linux and BSD will suffice.