This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Finding the path of the current binary?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]