Don't use the -G, or -dn options.
If the shared object being generated has dependencies on other shared objects, indicate they should be lazily loaded using the -zlazyload option (see "Lazy Loading of Dynamic Dependencies").
If the dynamic executable being generated has dependencies on other shared objects, and these dependencies do not reside in /usr/lib for 32-bit objects, or /usr/lib/64 for 64-bit objects, record their pathname in the output file using the -R option (see "Directories Searched by the Runtime Linker").
Establish direct binding information using -Bdirect (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 ..... |