To create a dynamic executable don't use the -G, or -d n options.
Indicate that the dependencies of the dynamic executable should be lazily loaded using the -z lazyload option. See Lazy Loading of Dynamic Dependencies.
If the dependencies of the dynamic executable do not reside in /usr/lib for 32–bit objects, or /usr/lib/64 for 64–bit objects, 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 External 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 ..... |