Chapter 3 87
Linker Tasks
Using Linker commands
+e reverse_tree
+e preorder_traversal
+e shift_reduce_parse
.
.
.
Note that the linker ignores lines in that option file that begin with a
pound sign (#). You can use such lines as comment lines or to temporarily
disable certain linker options in the file. For instance, the following
linker option file for an application contains a disabled -O option:
# Exporting only the "compress" symbol resulted
# in better run-time performance:
+e compress
# When the program is debugged, remove the pound sign
# from the following optimization option:
#-O
Passing Linker Options with LDOPTS
If you use certain linker options all the time, you may find it useful to
specify them in the LDOPTS environment variable. The linker inserts the
value of this variable before all other arguments on the linker command
line. For instance, if you always want the linker to display verbose
information (-v) and a trace of each input file (-t), set LDOPTS as
follows:
$ LDOPTS="-v -t" Korn and Bourne shell syntax.
$ export LDOPTS
Thereafter, the following commands would be equivalent:
$ ld /opt/langtools/lib/crt0.o -u main prog.o -lc
$ ld -v -t /opt/langtools/lib/crt0.o -u main prog.o -lc
Specifying Libraries with -l and l:
To direct the linker to search a particular library, use the -lname option.
For example, to specify libc, use -lc; to specify libm, use -lm; to
specify libXm, use -lXm.
Specifying Libraries (-l)
When writing programs that call routines not found in the default
libraries linked at compile time, you must specify the libraries on the
compiler command line with the -lx option. For example, if you write a C
program that calls POSIX math functions, you must link with libm.