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 ignore 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 Appendix D, Direct Bindings.
The following example combines the above points.
$ cc -o prog -R /home/lib -z ignore -z lazyload -B direct -L. \ -lfoo file1.o file2.o file3.o .....