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

Explanation sought for ld --as-needed



Hi.

A program I am about to maintain "borrows" a lot of it's CFLAGS and
LDFLAGS from it's parent program (it is a plugin, a shared library loaded
by dlload()). These CFLAGS and LDFLAGS contain a lot of library references
used by the parent, but only some of them are actually needed by the
plugin.

The default behaviour of ld seems to be to add all libraries passed
with -l to gcc as a dependency to the linked binary file, whether they
actually satisfy an unresolved symbol or not. Thus, my quite simple
plugin has a dependecny list (retrieved with ldd) that spans more
that a screen, and the RPM dependency list is not pretty as well.

So I read up on ld in the man page and found the --as-needed option.
It states that all libraries mentioned after this switch are only
added as a dependency if they actually satisfy a symbol. Just what I
needed. The default behaviour, as I observed, is --no-as-needed, btw.

The point of this mail is that it does not work. When I pass
-Wl,--as-needed to gcc in the linking stage, I end up with a binary
that links to libc, ld.so and libpthread. Which is not enough, and
I get unresolved references on load of the library.

Any hints on what I am doing wrong?

(Please note that the binary works just fine with all the
unnecesary libraries as a dependency. I just think it's ugly.)


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