LD(1) GNU Development Tools LD(1)
NAME
ld - The GNU linker
SYNOPSIS
ld [options] objfile ...
DESCRIPTION
ld combines a number of object and archive files, relocates their data and ties up symbol references. Usually the last step in compiling a program is to run ld.
ld accepts Linker Command Language files written in a superset of AT&T’s Link Editor Command Language syntax, to provide explicit and total control over the linking process.
This man page does not describe the command language; see the ld entry in "info" for full details on the command language and on other aspects of the GNU linker.
This version of ld uses the general purpose BFD libraries to operate on object files. This allows ld to read, combine, and write object files in many different formats---for example, COFF or "a.out". Different
formats may be linked together to produce any available kind of object file.
Aside from its flexibility, the GNU linker is more helpful than other linkers in providing diagnostic information. Many linkers abandon execution immediately upon encountering an error; whenever possible, ld
continues executing, allowing you to identify other errors (or, in some cases, to get an output file in spite of the error).
The GNU linker ld is meant to cover a broad range of situations, and to be as compatible as possible with other linkers. As a result, you have many choices to control its behavior.
OPTIONS
The linker supports a plethora of command‐line options, but in actual practice few of them are used in any particular context. For instance, a frequent use of ld is to link standard Unix object files on a standard,
supported Unix system. On such a system, to link a file "hello.o":
ld -o <output> /lib/crt0.o hello.o -lc
This tells ld to produce a file called output as the result of linking the file "/lib/crt0.o" with "hello.o" and the library "libc.a", which will come from the standard search directories. (See the discussion of the
-l option below.)
Some of the command‐line options to ld may be specified at any point in the command line. However, options which refer to files, such as -l or -T, cause the file to be read at the point at which the option appears in
the command line, relative to the object files and other file options. Repeating non‐file options with a different argument will either have no further effect, or override prior occurrences (those further to the left
on the command line) of that option. Options which may be meaningfully specified more than once are noted in the descriptions below.
Non‐option arguments are object files or archives which are to be linked together. They may follow, precede, or be mixed in with command‐line options, except that an object file argument may not be placed between an
option and its argument.
Usually the linker is invoked with at least one object file, but you can specify other forms of binary input files using -l, -R, and the script command language. If no binary input files at all are specified, the
linker does not produce any output, and issues the message No input files.
If the linker cannot recognize the format of an object file, it will assume that it is a linker script. A script specified in this way augments the main linker script used for the link (either the default linker
script or the one specified by using -T). This feature permits the linker to link against a file which appears to be an object or an archive, but actually merely defines some symbol values, or uses "INPUT" or "GROUP"
to load other objects. Specifying a script in this way merely augments the main linker script, with the extra