Originally, static libraries were contained in an archive file consisting just of a collection of relocatable object files. Later they evolved to optionally include a symbol table, to assist in finding the needed objects within a library. There their evolution ended, and dynamic libraries rose to ascendance.
One useful feature of dynamic libraries was that, more than just collecting multiple objects into a single file, they also included a list of their dependencies, such that one could specify just the name of a single dynamic library at link time, and all of its dependencies would be implicitly referenced as well. But static libraries lacked this feature, so if a link invocation was switched from using dynamic libraries to static libraries, the link command would usually fail unless it was rewritten to explicitly list the dependencies of the static library.
The GNU ar utility now supports a --record-libdeps option
to embed dependency lists into static libraries as well, and the libdep
plugin may be used to read this dependency information at link time. The
dependency information is stored as a single string, carrying -l
and -L arguments as they would normally appear in a linker
command line. As such, the information can be written with any text
utility and stored into any archive, even if GNU ar is not
being used to create the archive. The information is stored in an
archive member named ‘__.LIBDEP’.
For example, given a library libssl.a that depends on another library libcrypto.a which may be found in /usr/local/lib, the ‘__.LIBDEP’ member of libssl.a would contain
-L/usr/local/lib -lcrypto
Note any library search directories added in this way are only used to search for libraries which are also added the same plugin. They are not used for searching for libraries specified on the linker command line, linker scripts or other plugins. This does however present a problem if multiple archives with ‘__.LIBDEP’ entries are present as they will all be handled by the libdep plugin and thus they will share library search paths. This could result in a library being loaded from an unexpected location.