This document describes standard HP-UX commands you can use to determine library dependencies in your executable. |
To determine the shared libraries used by your executable, use the HP-UX chatr command: |
chatr executable \ >> $PLAN_DIR/stk.shared.libs
This returns a list of the shared libraries used by executable. For example:
a.out: shared executable shared library dynamic path search: SHLIB_PATH disabled second embedded path disabled first Not Defined shared library list: dynamic /usr/lib/libX11.2 dynamic /usr/lib/libXt.2 dynamic /usr/lib/libm.2 dynamic /usr/lib/libc.2 shared library binding: deferred static branch prediction disabled kernel assisted branch prediction enabled lazy swap allocation disabled text segment locking disabled data segment locking disabled data page size: 4K instruction page size: 4K
The shared library list section of the chatr output lists all of the shared libraries on which the executable a.out depends (in this case, there are four).
To determine dependencies on nested libraries, run chatr recursively on all of the shared libraries identified:
chatr library >> $PLAN_DIR/stk.shared.libs
Note: On HP-UX 11i on IPF, two forms of chatr are provided. The IPF chatr is in its normal location at /usr/bin/chatr. A PA chatr (for analyzing PA executables and libraries) can be accessed by setting the SDKROOT environment variable to/usr/ccs/pa before calling chatr. Unset SDKROOT to resume using the IPF-based chatr. |
The build process reports any archive files that it depends on if the linker is directed to produce this report. |
Modify the build line to include the -W1,-v flags, which produces verbose output including a list of all archive libraries used during the build.
In the following example, the build process loads the math, X11, and Xt libraries. These libraries are linked archive (using the -Wl,-a archive flag). Use the HP-UX grep and sort commands to filter the output. For example, to reduce output to a listing of the libraries used by your software:
grep Searching linker_output | sort -u
A library with a .a suffix is an archive library, while a library with a .sl suffix is a shared library.
% CC -Wl,-a archive -Wl,-v -o a.out \ testr.o -lm -lX11 -lXt | grep Searching \ | sort -u Searching library /usr/lib/libX11.a: Searching library /usr/lib/libXt.a: Searching library /usr/lib/libc.a: Searching library /usr/lib/libm.a: Searching library /usr/lib/milli.a: %
In this example, the application is using five archive libraries.
Libraries can be of different types (shared or archive, 32-bit or 64-bit, stripped or not stripped). You can use the HP-UX file command to determine the type of a library file. For example: |
% file /usr/lib/milli.a /usr/lib/milli.a: archive file \ -PA-RISC2.0 relocatable library % file /usr/lib/pa20_64/libc.2 libc.2: ELF-64 shared object file \ - PA-RISC 2.0 (LP64) %
In the following example, the file command is used to determine the type of binary files. The example program was compiled to produce a relocatable file and then an executable file. This was done for both 32-bit and 64-bit versions.
% CC -c +DA2.0w test.c % file test.o test.o: ELF-64 (Interim) relocatable object file - PA-RISC 2.0 (LP64) % CC +DA2.0w test.c % file a.out a.out: ELF-64 executable object file - PA-RISC 2.0 (LP64) % CC -c test.c % file test.o test2.o: PA-RISC2.0 relocatable object % CC test.c /usr/CCs/bin/ld: (Warning) At least one PA 2.0 object file (test.o) was detected. The linked output may not run on a PA 1.x system. % file a.out a.out: PA-RISC2.0 shared executable dynamically linked -not stripped %
Libraries can be created using objects compiled with either the CC or aC++ compiler. Do not mix CC and aC++ objects. You can use the nm command to determine what compiler was used to compile the objects in a given library. CC libraries will always have the noperfopt symbol in them. Use the nm andgrep commands as follows: |
% nm /opt/CC/lib/libGA.a | grep "noperfopt" __noperfopt__Graph_alg_c_00000ffb_sCC_ sub_ATTLC_|1073741992|extern|data|$SHORTDATA$ __noperfopt__dfs_c_00003802_nextv_| 1073741984|extern|data |$SHORTDATA$ __noperfopt__bfs_c_00003725_ intermediate_bfs_p_ATTLC_|1073741984| extern|data|$SHORTDATA$ __noperfopt__cycle_c_00003747_ cycle1_test_|1073742000|extern| data |$SHORTDATA$ __noperfopt__component_c_00003736_ internal_artic_pts_ATTLC_|1073741984| extern|data|$SHORTDATA$ % nm /opt/aCC/lib/libGA.a | grep "noperfopt" %
The noperfopt symbol indicates that /opt/CC/libGA.a is a CC library. Likewise, the lack of this symbol in the second example indicates that /opt/aCC/libGA.a is an aC++ library.