lorder
Order object files for linker
SYNOPSIS
lorder [file ...]
PARAMETERS
file
One or more object files (.o) or archive libraries (.a) to analyze. These files are scanned for their defined and undefined symbols to establish dependencies.
DESCRIPTION
The lorder command analyzes object files (.o) and archive libraries (.a) to determine their inter-dependencies. It produces a list of pairs of filenames, where the first file in a pair depends on the second file. This output is designed to be piped into tsort (topological sort) to generate a linear order of files suitable for linking by ld. It inspects the symbol tables of the input files, identifying undefined symbols (dependencies) and defined symbols (providers). lorder is particularly useful in Makefiles to ensure that static libraries and object files are passed to the linker in the correct order, which is crucial for resolving symbol references successfully. It does not perform the linking itself, but rather provides the necessary ordering information.
CAVEATS
lorder is primarily relevant for static linking scenarios where the order of archives and object files passed to the linker matters significantly.
It relies on an external utility, tsort, to produce a usable linking order from its pairwise output.
For dynamic linking, dependencies are typically handled by the linker and runtime loader through different mechanisms (e.g., DT_NEEDED entries in shared libraries), making lorder less applicable.
Its utility has somewhat diminished in modern build environments that often employ more sophisticated and automated dependency tracking solutions.
TYPICAL USAGE
The common pattern for using lorder is to pipe its output directly to tsort to obtain a linear, topologically sorted list of files that satisfies all dependencies.
Example: lorder *.o *.a | tsort
OUTPUT FORMAT
lorder produces a list of pairs of filenames on standard output, one pair per line, separated by a space. If file A depends on file B, the output will contain a line like A B
.
UNDERLYING MECHANISM
The command works by inspecting the symbol tables of the provided object files and libraries. It looks for undefined symbols (symbols that are referenced but not defined within the current file) and then checks if these symbols are defined in other input files, thus establishing a dependency.
HISTORY
lorder is a traditional Unix utility, typically part of the binutils suite or similar packages on Linux distributions. Its design reflects common practices for managing dependencies in older static linking environments. While its direct use in modern projects might be less frequent due to advanced build systems, it remains a foundational tool for understanding how static library dependencies were historically managed.