How do static libraries do linking to dependencies?

Static linking is just copying the whole items (functions, constants, etc) into the resulting executable. If a static library's code contains references to some shared library items, these references will become dependencies in the resulting executable. The same holds if you link a library instead of executable.

This thread discusses how it happens in Linux.


A static library is more or less a simple archive of unlinked binary object files (*.o or *.obj), when compiling the archive, no checking is done for dependencies. When one linked one's binary executable (or shared library / DLL) the linker checks for all the necessary dependencies and only then will alert you to any issues.


During the build process the compiler translates code into a temporary format, let's call it an object file. In the object file, there is a list of symbols that the compiler could not resolve, usually definitions elsewhere. The linking phase is in charge of resolving these symbols.

The build process feeds files to the linker until all symbols are resolved. There is no physical dependency lists, just lists of symbols to resolve. This allows for symbols to be resolved by using different libraries. For example, one may want to use a Windows library for Windows specific issues; a linux library for linux specific issues. This does not explicitly state that a program is dependent on a Windows library; it could also be dependent on the Linux one.

Some compilers can generate dependency lists, usually for usage in a build process. However, the ultimate responsibility is up to the programmer.