Most options to the link-editor can be passed through the compiler driver command-line. For the most part the compiler and the link-editor options do not conflict. Where a conflict arises, the compiler drivers usually provide a command-line syntax that allows you to pass specific options to the link-editor. However, you can instead provide options to the link-editor by setting the LD_OPTIONS
environment variable. For example:
$ LD_OPTIONS="-R /home/me/libs -L /home/me/libs" cc -o prog \ main.c -lfoo |
Here the -R and -L options will be interpreted by the link-editor and prepended to any command-line options received from the compiler driver.
The link-editor parses the entire option list looking for any invalid options or any options with invalid associated arguments. When either of these cases is found, a suitable error message is generated, and when the error is deemed fatal, the link-edit terminates. For example:
$ ld -X -z sillydefs main.o ld: illegal option -- X ld: fatal: option -z has illegal argument `sillydefs' |
Here the illegal option -X is identified, and the illegal argument to the -z option is caught by the link-editor's checking. If an option requiring an associated argument is mistakenly specified twice, the link-editor will provide a suitable warning but will continue with the link-edit. For example:
$ ld -e foo ...... -e bar main.o ld: warning: option -e appears more than once, first setting taken |
The link-editor also checks the option list for any fatal inconsistencies. For example:
$ ld -dy -a main.o ld: fatal: option -dy and -a are incompatible |
After processing all options, and if no fatal error conditions have been detected, the link-editor proceeds to process the input files.
See Appendix A, Link-Editor Quick Reference for the most commonly used link-editor options, and the ld(1) manual page for a complete description of all link-editor options.