How to prohibit shared library binding in absolute path?

Ralf Wildenhues Ralf.Wildenhues@gmx.de
Mon Mar 21 06:44:00 GMT 2011


Hello Pan,

* Pan ruochen wrote on Mon, Mar 21, 2011 at 07:28:47AM CET:
> 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

To avoid that, give the libraries a soname to get that recorded in
DT_NEEDED of consumers, rather than the name of the library used for
linking: -Wl,-soname,libs1.so

Cheers,
Ralf



More information about the Binutils mailing list