HP aC++/HP C Programmer's Guide (B3901-90036; A.06.26; September 2011)

NOTE: Use the aCC command to create a C++ shared library. This ensures that static
constructors and destructors are executed at appropriate times.
Example
The following example links util.o and creates the shared library util.so.
aCC -b -o util.so util.o
Using a Shared Library
To use a shared library, include the name of the library in the aCC command line or use
the-l option.
The linker links the shared library to the executable file it creates. Once you create an
executable file that uses a shared library, do not move the shared library as the dynamic
loader (dld.so) cannnot find it.
NOTE: Use the aCC command to link any program that uses a C++ shared library.
This ensures that static constructors and destructors in the shared library are executed at
appropriate times.
Example
The following example compiles prog.C, links it with the shared library util.so, and
creates the executable file a.out.
aCC prog.C util.so
Example of Creating and Using a Shared Library
The following command compiles the two files, Strings.C and Arrays.C, and creates
the two object files, Strings.o and Arrays.o. These object files contain
position-independent code (PIC):
aCC -c +z Strings.C Arrays.C
The following command builds the shared library, libshape.so, from the object files
Strings.oand Arrays.o:
aCC -b -o libshape.so Strings.o Arrays.o
The following command compiles a program, draw_shapes.C, that uses the shared
library, libshape.so:
aCC draw_shapes.C libshape.so
Linking Archive or Shared Libraries
When an archive and shared version of a particular library reside in the same directory,
the linker links in the shared version by default. You can override this behavior with the
-a linker option.
226 Tools and Libraries