Finding the path of the current binary?

Mike Hearn mike@theoretic.com
Fri Mar 7 19:16:00 GMT 2003


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



More information about the Libc-alpha mailing list