This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Linking against shared objects that reside at different paths on link-time versus runtime?
- From: Dun Peal <dunpealer at gmail dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Tue, 21 Jun 2011 11:15:51 -0500
- Subject: Linking against shared objects that reside at different paths on link-time versus runtime?
Hello!
I have the following line in a build script:
g++ [...] -Bdynamic /foo/bar.so
This line results in a binary which when analyzed with `ldd(1)`, shows
a dependency on `/foo/bar.so`.
The problem is that the link-time and runtime platforms are not the
same: at link-time, `bar.so` resides under `/foo`, while at runtime it
lives under `/baz`.
1) Is there a way to link `bar.so` such that at compile (more
precisely, link) time, it would be found at the former, while at
runtime it would be found on the latter?
2) The `ldd(1)` output for the binary shows some dependencies linked
"literally", e.g. `/foo/bar.so`, while others have a notation like
`libc.so.6 => /lib64/libc.so.6`. What's the difference?
3) Finally, is there a way to do runtime-platform-dependent links?
Ideally, the runtime platform be able to tell the binary to look for
`bar.so` under `/baz`. If that's not possible, being able to link
relatively (`../bar.so`) or relative to an environment-specified
location (`$HOME/qux/bar.so`) would be helpful.
I know a mishmash of related implementation details about
`LD_LIBRARY_PATH` etc that I use for ad-hoc troubleshooting, but would
appreciate a reference to a text that would organize the answer to
these questions in a coherent framework.
Thanks, D.