9

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

Dmitry Khalatov
  • 4,313
  • 3
  • 33
  • 39
  • Hi Dmitry. Look at [my question](http://stackoverflow.com/questions/9909528/how-can-i-remove-a-symbol-from-a-shared-object). Apparently, you can use [`objcopy -N foo`](http://linux.about.com/library/cmd/blcmdl1_objcopy.htm) to delete a shared object's symbols. – Ross Rogers Mar 28 '12 at 14:40

2 Answers2

11

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
  • 124,830
  • 17
  • 198
  • 235
5

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
  • 56,064
  • 19
  • 146
  • 246