Contents|Index|Previous|Next
Command line options for ld

The following example shows the options you can use on the ld command line. Following the example is a discussion of the options. This plethora of command-line options may seem intimidating, 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, use the following example. 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 search directories with the -L option .)

The command-line options to ld may be specified in any order, and may be repeated at will. Repeating most 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 specific option.

The exceptions—which may meaningfully be used more than once—are the following: -A, -b (or its synonym, -format), -defsym, -L, -l, -R, -u, and -( (or its synonym, --start-group).

The list of object files to be linked together, shown as objfile..., may follow, precede, or be mixed in with command-line options, except that an objfile 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 can not 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. See Linker scripts.

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, --oformat and -oformat are equivalent. 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, --oformat srec and --oformat=srec are equivalent. Unique abbreviations of the names of multiple-letter options are accepted.
 

 
Top|Contents|Index|Previous|Next