Behavior of run-time linker on 6.1-RELEASE

Jeffrey Horner jeff.horner at vanderbilt.edu
Thu Oct 5 11:58:21 PDT 2006


Hello all,

I'll apologize up front if my issue is not appropriate for this list or 
is answered elsewhere, but I thought I'd come straight to the source...

I've noticed that setting the RPATH of a binary will help find libraries 
that the binary has been linked against, but the RPATH of the binary is 
ignored when a library itself is linked to another library. Is this 
expected behavior?

Below is a demonstration of the behavior:

hornerj at biostatbsd ~/testrtl
$ cat main.c
#include <stdio.h>

void print_hello_lib1(void);

int main(int argc, char **argv){
         printf("hello from main\n");
         print_hello_lib1();
}
hornerj at biostatbsd ~/testrtl
$ cat lib1.c
#include <stdio.h>

void print_hello_lib2(void);

void print_hello_lib1(void){
         printf("hello from lib1\n");
         print_hello_lib2();
}
hornerj at biostatbsd ~/testrtl
$ cat lib2.c
#include <stdio.h>

void print_hello_lib2(void){
         printf("hello from lib2\n");
}
hornerj at biostatbsd ~/testrtl
$ make clean
rm *.o *.so runmain
hornerj at biostatbsd ~/testrtl
$ make
gcc -c main.c
gcc -fPIC -c lib2.c
gcc -shared  -Wl,-soname,lib2.so -o lib2.so lib2.o
gcc -fPIC -c lib1.c
gcc -shared  -Wl,-soname,lib1.so -o lib1.so lib1.o  lib2.so
gcc -L. -l1 -Wl,-rpath,`pwd` -o runmain main.o
hornerj at biostatbsd ~/testrtl
$ ./runmain
/libexec/ld-elf.so.1: Shared object "lib2.so" not found, required by 
"lib1.so"
$ gcc -v
Using built-in specs.
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.4.4 [FreeBSD] 20050518

So, I realize I can overcome this by setting the RPATH of lib1.so, but I 
just wanted to make sure that this is expected (since on another 
platform that's not necessary).

Thanks in advance,

Jeff
-- 
http://biostat.mc.vanderbilt.edu/JeffreyHorner


More information about the freebsd-hackers mailing list