User's Manual
Controlling Archive Library Loading with +[no]forceload
Use the +[no]forceload option to control how the linker loads object files from an archived
library. The +forceload instructs the linker to load all object files from an archive library. The
+noforceload option instructs the linker to only load those modules from an archive library that
is needed. The mode you select, either by default or explicitly, remains active until you change it.
The +noforceload option is the default. In the following example, main() references foo(),
which is a module in mylib.a. The function foo() does not reference any other module in
mylib.a and libc.a. If mylib.a contains foo.o and bar.o, then only foo.o is linked.
$ ld /opt/langtools/lib/hpux32/crt0.o main.o +vtype libraries mylib.a -lc
...
Selecting mylib.a[foo.o] to resolve foo
$ ld /opt/langtools/lib/hpux32/crt0.o main.o +forceload mylib.a -lc +vtype libraries
...
Selecting mylib.a[foo.o] to forcibly load
Selecting mylib.a[bar.o] to forcibly load
Passing Linker Options in a file with -c
The -c file option causes the linker to read command line options from the specified file. This is
useful if you have many -h or +e options to include on the ld command line, or if you have to
link with numerous object files. For example, suppose you have over a hundred +e options that
you need when building a shared library. You can place them in a file named eopts and force the
linker to read options from the file as follows:
$ ld -o libmods.sl -b -c eopts mod*.o
$ cat eopts Display the file.
+e foo
+e bar
+e reverse_tree
+e preorder_traversal
+e shift_reduce_parse
.
.
.
NOTE: 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 -u main prog.o -lc
$ ld -v -t -u main prog.o -lc
44 Determining How to Link Programs or Libraries (Linker Tasks)