[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Avoiding useless library dependencies

* Nikolaus Rath <Nikolaus@rath.org>, 2011-05-22, 21:17:
gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.7/src/llfuse.o -o build/lib.linux-x86_64-2.7/llfuse.so --as-needed -pthread -lfuse -lrt -ld

You want to use "-Wl,--as-needed", not "--as-needed". ("--as-needed" is a linker option, not a compiler option.)

Doesn't seem to make any difference:

gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions build/temp.linux-x86_64-2.6/src/llfuse.o -o build/lib.linux-x86_64-2.6/llfuse.so -Wl,--as-needed -pthread -lfuse -lrt -ldl
copying build/lib.linux-x86_64-2.6/llfuse.so -> src

$ ldd src/llfuse.so
	linux-vdso.so.1 =>  (0x00007fff63dff000)
	libfuse.so.2 => /usr/lib/libfuse.so.2 (0x00007fe771490000)
	libpthread.so.0 => /lib/libpthread.so.0 (0x00007fe771274000)
	libc.so.6 => /lib/libc.so.6 (0x00007fe770ef0000)
	librt.so.1 => /lib/librt.so.1 (0x00007fe770ce8000)
	libdl.so.2 => /lib/libdl.so.2 (0x00007fe770ae4000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fe77193b000)

Please keep in mind that ldd is recursive. Since libfuse.so.2 is linked with librt and libdl, these two will show up in ldd output regardless of whether llfuse is linked with them or not.

Use "readelf -d /path/to/library | grep NEEDED" instead of ldd.

Jakub Wilk

Reply to: