Creating a Dynamic Executable
-
To create a dynamic executable, don't use the
-G
or-d n
options. -
Use the link-editor
-z guidance
option. Guidance messages offer suggestions for link-editor options and other actions that can improve the resulting object. -
Indicate that the dependencies of the dynamic executable should be lazily loaded using the
-z lazyload
option. See Lazy Loading of Dynamic Dependencies. -
Avoid unneeded dependencies. Use
ldd
with the-u
option to detect and remove unneeded dependencies. See Shared Object Processing. Or, use the-z discard-unused=dependencies
option, which instructs the link-editor to record dependencies only to objects that are referenced. -
If the dependencies of the dynamic executable do not reside in the default search locations, record their path name in the output file using the
-R
option. See Directories Searched by the Runtime Linker. -
Establish direct binding information using
-B direct
. See Direct Bindings.
The following example combines the preceding points.
$ cc -o prog -R /home/lib -z discard-unused=dependencies -z lazyload -B direct -L. \
-lfoo file1.o file2.o file3.o ....