views:

856

answers:

2

I have two third-party libraries occasionally having the same symbol name exported. When the executable is loaded, ld usually picks the wrong one and I getting crash as a result. I cannot do too much about the content of these libraries, so may be there is a way to instruct ld how to find the proper imlementation ?

OS - Solaris 10, my program is built by autoconf/autotools/gcc, conflicting libraries are libclntsh (part of Oracle driver) and OpenLDAP. Unfortuinately, I cannot use Oracle's implementation of LDAP client - it lacks many features OpenLDAP has.

Edited: The linkage is as following: libclntsh.so->A.so->MAIN<-B.so<-libldap_r.so

+2  A: 

If you don't need to link in both shared libraries at compile time (which isn't clear from your question), you can use -Bdirect for the shared library. This will record for all symbols from the shared library where they had been found; if then at run-time a second definition of the symbol appears (from the other shared library), it will be ignored.

Martin v. Löwis
+2  A: 

One solution is to set the LD_PRELOAD environment variable to the library whose symbols should take precedence. (If that library has shared library dependencies of its own, you may need to preload all of its dependencies; just set LD_PRELOAD to the list of dependent libraries, separated by spaces.)

Josh Kelley