pthread_stubs.5 (2010 09)
p
pthread_stubs(5) pthread_stubs(5)
libc.2. The dependency list of the first case is:
a.out
// \
lib1 lib2 libc
||
libc libpthread
Therefore the load graph is constructed as:
lib1.sl --> lib2.sl -->libc.2 --> libpthread.1
This is the desired behavior for non-threaded applications, but causes threaded applications (that use
either libpthread or libcma) to fail.
lib1.sl specifies -lc, lib2.sl specifies
-lpthread and no -lpthread on a.out.
$ cc -c +z +DA2.0W lib1.c lib2.c
lib1.c:
lib2.c:
$ ld -b -o lib1.sl -lc lib1.o
$ ld -b -o lib2.sl -lpthread lib2.o
$ cc +DA2.0W thread.c -L. -l1 -l2
$ a.out
Error
$ ldd a.out
lib1.sl => ./lib1.sl
lib2.sl => ./lib2.sl
libc.2 => /usr/lib/pa20_64/libc.2
libc.2 => /lib/pa20_64/libc.2
libpthread.1 => /lib/pa20_64/libpthread.1
libdl.1 => /usr/lib/pa20_64/libdl.1
lib2.sl specifies -lpthread and no -lpthread on a.out.
$ ld -b -o lib1.sl lib1.o
$ ld -b -o lib2.sl -lpthread lib2.o
$ cc +DA2.0W thread.c -L. -l1 -l2
$ a.out
Error
$ ldd a.out
lib1.sl => ./lib1.sl
lib2.sl => ./lib2.sl
libc.2 => /usr/lib/pa20_64/libc.2
libpthread.1 => /lib/pa20_64/libpthread.1
libdl.1 => /usr/lib/pa20_64/libdl.1
The same problem will occur if
libcma is listed as a dependent library of a shared library, and you
would need to link the executable with -lcma.
Recommendation for Example 3
For threaded applications, run the executable with
LD_PRELOAD set to the libpthread library or link
the executable with -lpthread:
Use
LD_PRELOAD to load libpthread first
$ ld -b -o lib1.sl lib1.o
$ ld -b -o lib2.sl -lpthread lib2.o
6 Hewlett-Packard Company − 6 − HP-UX 11i Version 3: September 2010