views:

892

answers:

3

So. I have a problem where I have two versions of GCC on a machine.
3.4.6 and 4.1

This is due to some dependency issues with a new piece of software. (requires glibc 4.1)

When I go to link this new software with the 4.1 libraries it links fine. However, when it comes to executing the software it can't find the library, because it is looking at 3.4.6 in my LD_LIBRARY_PATH. If I set LD_LIBRARY_PATH to the 4.1 lib it blows up the shell,among killing other things, because the 3.4.6 libraries are used for that.

Its a bit of a catch 22.

Is there any way that at link time I can give an absolute path to that shared library without using the LD_LIBRARY_PATH?

This way I can hopefully have both versions, but only use 4.1 for this specific application?

+6  A: 

You mean an absolute path that's used when the program is started and that's favored when looking for libraries? rpath is exactly that. It will overwrite the default search path and stuff set in LD_LIBRARY_PATH. Just tell gcc to pass it through to the linker:

g++ -Wl,-rpath,/usr/lib/my_4.1 -omy_binary *.cpp

You can make it show you the search processing (use help to make it give you more options):

[js@HOST2 cpp]$ LD_DEBUG=libs ./a.out
  5859:     find library=libc.so.6 [0]; searching
  5859:      search path=/usr/lib/my_4.1/tls/i686/sse2:/usr/lib/my_4.1/tls/i686:
               /usr/lib/my_4.1/tls/sse2:/usr/lib/my_4.1/tls:
               /usr/lib/my_4.1/i686/sse2:/usr/lib/my_4.1/i686:
               /usr/lib/my_4.1/sse2:/usr/lib/my_4.1  (RPATH from file ./a.out)
  5859:       trying file=/usr/lib/my_4.1/tls/i686/sse2/libc.so.6
  5859:       ....
  5859:      search cache=/etc/ld.so.cache
  5859:       trying file=/lib/libc.so.6  (note: found here!)
  5859:
Johannes Schaub - litb
+1  A: 

not really an answer to your question, but an alternate solution:

you should be able to fix up your issues by adding your new lib path to /etc/ld.so.conf and running ldconfig as root.

Hasturkun
A: 

Can't you set LD_LIBRARY_PATH just for the application that needs it? I.e. instead of setting it globally as an exported variable, run your program as

LD_LIBRARY_PATH=/path/to/4.1/libs my_executabel

?

-k

Ketil