Installation guide
Now, suppose you enter the same command, but use the shared library
instead of the archive library:
% cc program1.o -lspecial_math program2.o
This command succeeds, but prints a warning message indicating that the
symbol is undefined.
To correctly link this application, enter the following command:
% cc program1.o program2.o -lspecial_math
In general, always specify the −l option last in the command line.
8.1.2.2 When Symbols Are Defined More than Once
Symbol name resolution when using shared libraries is similar to name
resolution when using static libraries. Symbol names are resolved
according to the order in which the object file or shared object containing
the symbols appears on the command line. The linker typically takes the
leftmost definition for any symbol that must be resolved.
The sequence in which names are resolved proceeds as if the link
command line were stored in the executable. When the program runs, all
referenced symbols must be resolved. The program aborts if any undefined
symbols are referenced.
When you link your application with shared libraries, do not define the
same symbol twice. For example, you cannot use the following cc command
to link an application that contains a shared library:
% cc program1.o libspecial_math.so program2.o libspecial_math.a
This command succeeds, but prints warning messages indicating that a
symbol is defined multiple times.
8.1.3 Using Your Makefile with Shared Libraries
If you use the make command to build your ULTRIX application, you can
use it to build a DIGITAL UNIX application that uses shared libraries. You
need not modify your makefile file to use it with shared libraries. Unlike
ULTRIX systems, linking with shared libraries is the default on DIGITAL
UNIX systems.
The following example shows a Makefile file that links with shared
libraries on a DIGITAL UNIX system:
# Makefile for the Math Program
all: math.h program1.o program2.o
cc program1.o program2.o -L/usr/person -lspecial_math
8–4 Postmigration Programming Features