Installation guide
program1.o: project.h
cc -c program1.c
8.1.4 Creating Shared Libraries from Object Files
To create a shared library:
1. Create one or more source files that define the routines you want to
include in the library.
2. Compile the source file into an object file, as shown:
% cc -c special_math.c
3. Create the library by using the ld command. (You cannot use the cc
command to create a shared library. You must invoke the ld command
directly.) The following shows a sample ld command:
% ld -shared -no_archive -
o libspecial_math.so special_math.o -lc
In this example, the −shared option specifies creating a shared (rather
than an archive) library. The −no_archive option tells the linker to
resolve all symbols from shared libraries only. The −o option specifies
the name of the shared library.
For this command to succeed without printing warning messages, all
symbols in the special_math.o object must be resolved. In this case,
the special_math.o object references symbols that are defined in
libc. The −lc option specifies that ld search libc to resolve those
symbols. The ld linker searches the /usr/shlib directory for libc,
by default.
If the shared library you are creating references symbols defined in
another shared library, you must name the other shared library in the
ld command line. Name the shared library last in the command line to
ensure that the linker encounters the reference to the symbol before it
encounters the definition of the symbol.
For more information on using ld to create shared libraries, see ld
(1).
8.1.5 Creating Shared Libraries from Archive Libraries
You can also create a shared library from an existing static (archive)
library by using the ld command. The following example converts the
static library, old.a, into the shared library, libold.so:
% ld -shared -no_archive -o libold.so -all old.a -none -lc
Postmigration Programming Features 8–5