Archives

Overview

A static library is a format for packaging multiple relocatable object files together. When the linker builds the output executable, it only copies the object modules in the library referenced by the application program.

On Linux systems, static libraries are typically stored on disk as an archive. An archive is a collection of concatenated relocatable object files with a header that describes the size and location of each member object file.

Symbol Resolution

During symbol resolution, the linker scans the relocatable object files and archives left to right in the same order they appear on the command line. During this scan, the linker maintains three sets:

For each input file, the linker determines if its an object file or archive. If the former, the three sets are updated. If the latter, the linker attempts to match symbols in U against those defined by members of the archive. For any match, the three sets are further updated.

If U is nonempty when the linker finishes scanning all input files, it prints an error and terminates. Otherwise it merges and relocates the object files in E to build the executable.

Powered by Forestry.md