3.8 Developing Libraries
This section disc
usses developing shared and archive libraries for HP XC applications. Building
a library general
ly consists of two phases:
• Compiling sources to objects
• Assembling the objects into a library
-Usingthear archi
ve tool fo r archive (.a)libraries
- Using the linker (possibly indirectly by means of a com piler) for shared (.so) libraries.
For sufficiently small shared objects, it is often po ssible to c om bine the two steps.
A common technique i s to build the archive library f irst, and then build the shared library from
the archive library ( usin g the linker’s -whole-archive switch ).
For libraries that do not use HP-MPI, it is recommended that the sources be compiled with the
standard compilers (such as gcc), just as they would be on other UNI X- lik e platforms.
For libraries that do u
se HP-MPI, it is possible to use the HP-MPI compiler utilities (such as
mpicc) to compile the s
ources to objects. For example:
$ mpicc -c -g foo.c
To assemble an archive library, use the ar archiv e tool as you would on other UNIX-like
platforms. To assemble a shared library, use the linker (possibly indirectly by means of a
compiler) as you would on other UNI X-like platforms.
Once the library is built, it can be used to build applications, just as other libraries are used,
for both serial applications (with the stand ard compilers) and parallel applications (with the
HP-MPI compiler utilities).
Note that for shared libraries it is necessary to use LD_LIBRARY_PATH to include the directory
containing the shared library, just as you would on other UNIX-like plat for ms.
3.8.1 Designing Libraries for XC4000
This section discusses the issues surrounding the d esign of libraries for XC4000 on the HP
XC system.
A user designing a library for use on an HP XC XC4000 system can supply a 32-bit library
and/or a 64-bit library. H P recommends that both are supported to provide flexibility, and to
make it easy to get the 64-bit advantages locally, but be able to take the 32-bit variant to an
x86-class machine or run a 32-bit variant imported from an x86-class machine.
It is the library designer’s res
ponsibility to make sure 32-bit and 64-bit object files do not
collide during the build proces
s. This can be done by "cleaning" object files from the directories
between builds, or (as is more co
mmon) maintaining separate directories for the different types
of objects. Separate directori
es also makes it easy to maintain production versions disti nct
from debuggable versions.
Different compilers have d ifferent ways to select 32-bit or 64-bit compilations and links.
Consult the documentation for the compiler for this information.
For released libraries, dynam ic and archive, the usual custom is to have a ../lib directory
that contains the libraries. This, by itself, will work if the 32-bit and 64-bit libraries have
different names. However, HP recom mends an alternativ e method. The dynamic linker, during
its attempt to load libraries, will suffix candi date directories with the machine type. For 32- bi t
binaries on XC4000, it uses i686 and for 64-bit binaries it uses x86_64. HP recommends
structuring directories to reflect this behavior. Therefore, if your released directory structure
looks like Example 3-1, then it is only necessary to ensure that th e LD_LIBRARY_PATH
Developing Applications 3-9
Commentaires sur ces manuels