Use the -G option (-dy is optional as it is implied by default).
Input relocatable objects should be built from position-independent code. Use the -ztext option to enforce this requirement (see "Position-Independent Code").
Establish the shared objects public interface by defining the global symbols that should be visible from this shared object, and reducing any other global symbols to local scope. This definition is provided by the -M option together with an associated mapfile, and is covered in more detail in Appendix B, Versioning Quick Reference.
Use a versioned name for the shared object to allow for future upgrades (see "Coordination of Versioned Filenames").
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 shared object 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 "Shared Objects With Dependencies").
Self-contained shared objects offer maximum flexibility, and are produced when the object expresses all dependency needs. Use the -zdefs to enforce this self containment (see "Generating a Shared Object").
Optimize relocation processing by placing all relocations into the single .SUNW_reloc section. Use the -zcombreloc option.
Avoid unneeded dependencies; use the -zignore option, which instructs the link-editor to only record dependencies to objects which are referenced.
If interposing symbols will not be used on this object or its dependencies, establish direct binding information with -Bdirect (see "External Bindings").
The following example combines the above points:
$ cc -c -o foo.o -Kpic foo.c $ cc -M mapfile -G -o libfoo.so.1 -z text -z defs -B direct -z lazyload \ -z combreloc -z ignore -R /home/lib foo.o -L. -lbar -lc |
If the shared object being generated will be used as input to another link-edit, record within it the shared object's runtime name using the -h option (see "Recording a Shared Object Name").
Make the shared object available to the compilation environment by creating a file system link to a non-versioned shared object name (see "Coordination of Versioned Filenames").
The following example combines the above points:
$ cc -M mapfile -G -o libfoo.so.1 -z text -z defs -B direct -z lazyload \ -z combreloc -z ignore -R /home/lib -h libfoo.so.1 foo.o -L. -lbar -lc $ ln -s libfoo.so.1 libfoo.so |
Consider the performance implications of the shared object; maximize shareability (see "Maximizing Shareability") and minimize paging activity (see "Minimizing Paging Activity"), reduce relocation overhead, especially by minimizing symbolic relocations (see "Reducing Symbol Scope"), and allow access to data via functional interfaces (see "Copy Relocations").