This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
Finding the path of the current binary?
- From: Mike Hearn <mike at theoretic dot com>
- To: libc-alpha at sources dot redhat dot com
- Date: 07 Mar 2003 19:17:55 +0000
- Subject: Finding the path of the current binary?
- Organization:
Hi,
I'm wondering if there is a way to get the absolute path or soname of
the library the code is loaded from.
The reason I ask is that I'd like to know how to build relocatable
libraries, for instance that load data files. For executable binaries,
on Linux you can read /proc/self/exe to get a symlink to the binary, and
then use a relative path to get to say "../share/foobar/foo.jpg", and
for libraries you can read /proc/self/maps and try and find yourself in
there, but you need to know the soname.
Ideally, I don't want to embed the soname into the code itself, I'd
rather just call a function that gets the path of whereever the lib
happens to be located.
I know the linker will expand out ${ORIGIN}, which is ideal, but I don't
know a way of getting that information into a string. Any tips on where
I might look?
thanks -mike