This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

bug in ld -rpath ??



I am having trouble using the "-rpath" switch to GNU ld.  I assume that it
should work like the "-R" switch to the Solaris linker, but it does not
appear to.  Here is an example.  I create a shared library called liba.so
that refers to another shared library, libused_by_a.so.  When I create
liba.so, I use the -rpath switch to ld, so that liba.so "knows" where to
find libused_by_a.so.  On Solaris, both the run-time dynamic linker and ld
use this information whenever I link with liba.so.  The GNU linker, however,
seems to ignore the rpath information embedded in liba.so when I link with it.

Here are two transcripts.  The first is on Solaris, the second on a machine
running Linux 6.0 with gcc 2.95.2 and binutils 2.10 installed.  On Solaris,
my use of liba.so succeeds, but with GNU ld it fails.

Does GNU ld have a broken "-rpath" switch, or is GNU ld behaving as you
intend?  If the bug only appears in the 2.10 binutils release, is it safe to
use an earlier linker with gcc version 2.95.2?

Thanks very much.

				bob

====================

lion <81>  cd /tmp
lion <82>  mkdir a u
lion <83>  echo 'int a(){ used_by_a(); }' > a/a.c
lion <84>  echo 'int used_by_a() { }' > u/u.c


lion <85>  cd /tmp/u
lion <86>  cc -c u.c
lion <87>  cc -G -o libused_by_a.so u.o


lion <88>  cd /tmp/a
lion <89>  cc -c a.c
lion <90>  cc -G -o liba.so a.o
lion <91>  cc -L/tmp/u -R/tmp/u -G -o liba.so a.o -lused_by_a
lion <92>  ldd liba.so
	libused_by_a.so =>	 /tmp/u/libused_by_a.so


lion <93>  cd /tmp
lion <94>  echo 'int main() { a(); }' > main.c
lion <95>  cc -c main.c
lion <96>  cc -L/tmp/a -R/tmp/a main.o -la

lion <97>  ldd a.out
	liba.so =>	 /tmp/a/liba.so
	libc.so.1 =>	 /usr/lib/libc.so.1
	libused_by_a.so =>	 /tmp/u/libused_by_a.so
	libdl.so.1 =>	 /usr/lib/libdl.so.1
lion <98>  ./a.out
lion <99>  

====================

vole <106>  cd /tmp
vole <107>  mkdir a u
vole <108>  echo 'int a(){ used_by_a(); }' > a/a.c
vole <109>  echo 'int used_by_a() { }' > u/u.c


vole <110>  cd /tmp/u
vole <111>  gcc -c u.c
vole <112>  gcc -shared -o libused_by_a.so u.o


vole <113>  cd /tmp/a
vole <114>  gcc -c a.c
vole <115>  gcc -shared -o liba.so a.o
vole <116>  gcc -shared -L/tmp/u -Wl,-rpath /tmp/u -o liba.so a.o -lused_by_a

vole <117>  ldd liba.so
	libused_by_a.so => /tmp/u/libused_by_a.so (0x40002000)
	libc.so.6 => /lib/libc.so.6 (0x4000b000)
	/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x80000000)


vole <118>  cd /tmp
vole <119>  echo 'int main() { a(); }' > main.c
vole <120>  gcc -c main.c
vole <121>  gcc -v -L/tmp/a -Wl,-rpath /tmp/a main.o -la
Reading specs from /sw/external/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/specs
gcc version 2.95.2 19991024 (release)
 /sw/external/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /sw/external/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/crtbegin.o -L/tmp/a -L/sw/external/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2 -L/sw/external/gcc-2.95.2/lib -rpath /tmp/a main.o -la -lgcc -lc -lgcc /sw/external/gcc-2.95.2/lib/gcc-lib/i686-pc-linux-gnu/2.95.2/crtend.o /usr/lib/crtn.o
/sw/external/binutils-2.10/bin/ld: warning: libused_by_a.so, needed by /tmp/a/liba.so, not found (try using --rpath)
/tmp/a/liba.so: undefined reference to `used_by_a'
collect2: ld returned 1 exit status

vole <122>  

====================

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]