Kenwood HP 9000 Personal Computer User Manual


 
164 Chapter 5
Creating and Using Libraries
Caution When Mixing Shared and Archive Libraries
Caution When Mixing Shared and
Archive Libraries
Mixing shared and archive libraries in an application is not
recommended and should be avoided. That is, an application should use
only shared libraries or only archive libraries.
Mixing shared and archive libraries can lead to unsatisfied symbols,
hidden definitions, and duplicate definitions and cause an application to
abort or exhibit incorrect behavior at run time. The following examples
illustrate some of these problems.
Example 1: Unsatisfied Symbols
This example (in 32-bit and 64-bit +compat mode) shows how mixing
shared and archive libraries can cause a program to abort. Suppose you
have a main program, main(), and three functions, f1(), f2(), and
f3() each in a separate source file. main() calls f1() and f3() but not
f2():
$ cc -c main.c f1.c f2.c Compile to relocatable object code.
$ cc -c +z f3.c Compile to position-independent code
Figure 5-7
Next suppose you put f3.o into the shared library lib3.sl and f1.o
and f2.o into the archive library lib12.a:
$ ld -b -o lib3.sl f3.o Create a shared library.
$ ar qvc lib12.a f1.o f2.o Create an archive library.