Linker and Libraries Guide

Dynamic Mode

This is the default mode of operation for the link-editor. It can be enforced by specifying the -dy option, but is implied when not using the -dn option.

Under this mode, relocatable objects, shared objects and archive libraries are acceptable forms of input. Use of the -l option will result in a directory search, where each directory is searched for a shared object, and if none is found the same directory is then searched for an archive library. A search for archive libraries only, can be enforced by using the -Bstatic option (see "Linking With a Mix of Shared Objects and Archives").

Creating a Shared Object

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

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

Creating a Dynamic Executable

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 .....