HP UX Software Transition Kit (STK) manual Mixed Mode Shared Libraries

Models: UX Software Transition Kit (STK)

1 228
Download 228 pages 54.84 Kb
Page 130
Image 130

Figure 30 Search Order of Dependent Libraries

The commands to build the libraries and the executable in Figure 30 (page 130) are given below. Note the link order of libraries in steps 2 and 3:

1.First, the dependent shared libraries for libA are built. (Other libraries are also built.)

$

ld -b libDK.o

-o libDK.so

 

$

ld -b libLH.o -o libLH.so

 

$

ld -b libD.o

-IDK -ILH -o libD.so

libA dependent shared library

$

ld -b libE.o

-o libE.so

libA dependent shared library

$

ld -b libF.o

-o libF.so

libA dependent shared library

$

ld -b libB.o

-o libB.so

 

$

ld -b libC.o

-o libC.so

 

2.Next, libA.o is linked to its dependent libraries and libA.so is built. $ ld -b libA.o -lD -lE -lF -o libA.so

3.Finally, main.o is linked to its shared libraries. $ cc main.o -lA -lB -lC -o main

If a procedure called same_name() is defined in libD.so and libB.so, main calls same_name() in libB.so. If you use mixed mode shared libraries, the search mechanism may produce unexpected results. For the following command, libA.so and its dependent libB.so are compatibility mode libraries, and libC.so and libD.so are standard mode libraries.

$ ld -b libF.o +compat -L.-lA -lC -o libF.so

The libF.so library is a compatibility mode library, but its dependent libC.so is a standard mode library. The linker uses depth-first searching mechanisms because the highest-level library is in compatibility mode.

Mixed Mode Shared Libraries

A mixed mode shared library is a library whose children are all of one type (for example, +compat), but whose grandchildren may be of the other mode. This poses some problems when linking and loading the libraries. To help resolve this, the linker treats each library as having any mode.

Therefore, when it sees a compatibility mode library, it searches for it using the PA-32-style

130 Creating and Using Libraries

Page 130
Image 130
HP UX Software Transition Kit (STK) manual Mixed Mode Shared Libraries, Search Order of Dependent Libraries