Creating a Dynamic Executable
-
To create a dynamic executable, don't use the
-Gor-d noptions. -
Use the link-editor
-z guidanceoption. 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 lazyloadoption. See Lazy Loading of Dynamic Dependencies. -
Avoid unneeded dependencies. Use
lddwith the-uoption to detect and remove unneeded dependencies. See Shared Object Processing. Or, use the-z discard-unused=dependenciesoption, 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
-Roption. 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 ....