8 developing libraries, 1 designing libraries for xc4000, Section 3.8) – HP XC System 2.x Software User Manual

Page 49

Advertising
background image

3.8 Developing Libraries

This section discusses developing shared and archive libraries for HP XC applications. Building
a library generally consists of two phases:

Compiling sources to objects

Assembling the objects into a library

-

Using the

ar

archive tool for archive (

.a

) libraries

-

Using the linker (possibly indirectly by means of a compiler) for shared (

.so

) libraries.

For sufficiently small shared objects, it is often possible to combine the two steps.

A common technique is to build the archive library first, and then build the shared library from
the archive library (using 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 UNIX-like platforms.

For libraries that do use HP-MPI, it is possible to use the HP-MPI compiler utilities (such as

mpicc

) to compile the sources to objects. For example:

$ mpicc -c -g foo.c

To assemble an archive library, use the

ar

archive 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 UNIX-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 standard 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 platforms.

3.8.1 Designing Libraries for XC4000

This section discusses the issues surrounding the design 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. HP 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 responsibility to make sure 32-bit and 64-bit object files do not
collide during the build process. This can be done by "cleaning" object files from the directories
between builds, or (as is more common) maintaining separate directories for the different types
of objects. Separate directories also makes it easy to maintain production versions distinct
from debuggable versions.

Different compilers have different ways to select 32-bit or 64-bit compilations and links.
Consult the documentation for the compiler for this information.

For released libraries, dynamic 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 recommends an alternative method. The dynamic linker, during
its attempt to load libraries, will suffix candidate directories with the machine type. For 32-bit
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 the

LD_LIBRARY_PATH

Developing Applications

3-9

Advertising