How to prohibit shared library binding in absolute path?

Pan ruochen panruochen@gmail.com
Mon Mar 21 06:28:00 GMT 2011


Hi All,

I link an application against some shared libraries in absolute-path format.
The linker writes the absolute path into the output application.

$gcc -fpic -shared -fvisibility=hidden -O2 -o libs1.so s1.c
$gcc -fpic -shared -fvisibility=hidden -O2 -o libs2.so s2.c
$gcc -O2 -o foo -Wl,-rpath=. main.c /home/admin/x1/libs1.so libs2.so
$readelf -a foo | grep Shared
 0x00000001 (NEEDED)                     Shared library:
[/home/admin/x1/libs1.so]
 0x00000001 (NEEDED)                     Shared library: [libs2.so]
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]

The shared libraries couldn't be moved to other directories since `foo' inform
the dynamic linker that libs1.so must be inside the directory /home/admin/x1.
This will cause problems for cross building.

I expect to get while linking agaist /home/admin/x1/libs1.so:
$readelf -a foo | grep Shared
 0x00000001 (NEEDED)                     Shared library: [libs1.so]
 0x00000001 (NEEDED)                     Shared library: [libs2.so]
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]

How to do?

PRC
Mar 21,2011



More information about the Binutils mailing list