You can either run the link-editor directly from the command-line or have a compiler driver invoke it for you. In the following two sections the description of both methods are expanded. However, the latter is the preferred choice, as the compilation environment is often the consequence of a complex and occasionally changing series of operations known only to compiler drivers.
When you invoke the link-editor directly, you have to supply every object file and library required to build the intended output. The link-editor makes no assumptions about the object modules or libraries you meant to use in building the output. For example, when you issue the command:
$ ld test.o |
the link-editor builds a dynamic executable named a.out using only the input file test.o. For the a.out to be a useful executable, it should include start-up and exit processing code. This code can be language or operating system specific, and is usually provided through files supplied by the compiler drivers.
Additionally, you can also supply your own initialization and termination code. This code must be encapsulated and labeled correctly for it to be correctly recognized and made available to the runtime linker. This encapsulation and labeling is also provided through files supplied by the compiler drivers.
In practice, when creating runtime objects such as executables and shared objects, it is recommended that a compiler driver be used to invoke the link-editor. Invoking the link-editor directly is recommended only when creating intermediate relocatable objects using the -r option.
The conventional way to use the link-editor is through a language-specific compiler driver. You supply the compiler driver, cc(1), f77(1), and so forth, with the input files that make up your application, and the compiler driver adds additional files and default libraries to complete the link-edit. These additional files can be seen by expanding the compilation invocation, for example:
$ cc -# -o prog main.o /usr/ccs/bin/ld -dy /opt/COMPILER/crti.o /opt/COMPILER/crt1.o \ /usr/ccs/lib/values-Xt.o -o prog main.o \ -YP,/opt/COMPILER/lib:/usr/ccs/lib:/usr/lib -Qy -lc \ /opt/COMPILER/crtn.o |
This is an example; the actual files included by your compiler driver and the mechanism used to display the link-editor invocation might differ.