Re: Same symbol, two libraries



Frank Cusack wrote:
On 24 Apr 2006 13:35:27 -0700 u.int.32.t@xxxxxxxxx wrote:
I'm using two libraries (really two versions of the same), lib7.so and
lib8.so.

Both of these define symbols keep and update.

In my executable, I want to use lib7.so's version of keep and lib8.so's
version of update.

Any ideas on how I can do this?

If you know the link order, you can use dlsym() to get both versions of
keep/update. Since you know the link order, you'll know which is which.

If you don't know the link order, you can dlopen() the libraries yourself
before calling dlsym().

You might want to do this in an interposed library (LD_PRELOAD) instead
of in your app.

If you have the source for the libraries, make keep and update weak aliases
for keep_lib7 and keep_lib8. Then you can just call the specific version
instead of the alias in your app (perhaps by #define rather than at runtime).

You could create a shared lib which defines filters for keep and update
and link against that before linking against lib7 and lib8. Those filters
would point to the appropriate versions.

There might be a way to use direct binding and ild to link against lib7
first, for keep, then lib8 for update.

I've tried the dlsym method and the problem is that when keep is called
from v7, calls within keep resolve to calls for the newer library,
which result in coredumps... I'll google a bit more.

.



Relevant Pages

  • Re: A question about linking objects
    ... In my mind I'm thinking about the gnu g++ compiler. ... It's usually a bad idea to have code that's dependent on link order. ... Libraries are usually just repositories of a collection of compiled ... load time. ...
    (comp.programming)
  • Re: relative ordering of static libraries
    ... The C standard does not deal with link order at all. ... Change the algorithm of searching for the libraries named in ... instances of this option in a single c99 command ...
    (comp.lang.c)
  • Re: Same symbol, two libraries
    ... Since you know the link order, ... If you have the source for the libraries, make keep and update weak aliases ... and link against that before linking against lib7 and lib8. ... There might be a way to use direct binding and ild to link against lib7 ...
    (comp.unix.solaris)