The gnu linker
is meant to cover a broad range of situations, and to be as compatible as possible
ld
with other linkers. As a result, you have many choices to control its behavior.
3.1. Command Line 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
standard, supported Unix system. On such a system, to link a file
ld -o
/lib/crt0.o hello.o -lc
output
This tells
to produce a file called
ld
and the library
hello.o
discussion of the
-l
Some of the command-line options to
options which refer to files, such as
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
the linker does not produce any output, and issues the message
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
appears to be an object or an archive, but actually merely defines some symbol values, or uses
or
to load other objects. Note that specifying a script in this way merely augments the main
GROUP
linker script; use the
For options whose names are a single letter, option arguments must either follow the option letter
without intervening whitespace, or be given as separate arguments immediately following the option
that requires them.
For options whose names are multiple letters, either one dash or two can precede the option name;
for example,
-trace-symbol
this rule. Multiple letter options that start with a lower case 'o' can only be preceeded by two dashes.
This is to reduce confusion with the
whereas
magic
-omagic
Arguments to multiple-letter options must either be separated from the option name by an equals sign,
or be given as separate arguments immediately following the option that requires them. For example,
-trace-symbol foo
of multiple-letter options are accepted.
output
, which will come from the standard search directories. (See the
libc.a
option below.)
ld
or
-l
, and the script command language. If no binary input files at all are specified,
-R
). This feature permits the linker to link against a file which
-T
option to replace the default linker script entirely. Chapter 4 Linker Scripts.
-T
and
-trace-symbol
option. So for example
-o
sets the NMAGIC flag on the output.
and
-trace-symbol=foo
is to link standard Unix object files on a
ld
as the result of linking the file
may be specified at any point in the command line. However,
, cause the file to be read at the point at which the option
-T
are equivalent. Note--there is one exception to
are equivalent. Unique abbreviations of the names
Chapter 3.
Invocation
:
hello.o
/lib/crt0.o
.
No input files
sets the output file name to
-omagic
with
INPUT
Need help?
Do you have a question about the ENTERPRISE LINUX 3 - USING ID and is the answer not in the manual?
Questions and answers