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
...
Selecting mylib.a[foo.o] to resolve foo
$ ld /opt/langtools/lib/hpux32/crt0.o main.o +forceload mylib.a
...
Selecting mylib.a[foo.o] to forcibly load Selecting mylib.a[bar.o] to forcibly load
Passing Linker Options in a file with
The
$ ld
$ 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
#Exporting only the "compress" symbol resulted
#in better
+e compress
#When the program is debugged, remove the pound sign
#from the following optimization option:
#
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
$
Thereafter, the following commands would be equivalent:
$ ld
$ ld
44 Determining How to Link Programs or Libraries (Linker Tasks)