Up: Plugins   [Contents][Index]


4.1 Static Library Dependencies Plugin

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

Up: Plugins   [Contents][Index]