HP aC++/HP C A.06.28 Programmer's Guide Integrity servers (769150-001, March 2014)

Creating a Shared Library
To create a shared library from one or more object files, use the -b option at link time. (The object
files must have been compiled with +z or +Z.) The -b option creates a shared library rather than
an executable file.
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.
NOTE: Use the +A option when using only archive libraries to create a completely archived
executable.
The -a option identifies the library type for the linker. The -a option is positional and applies to
all subsequent libraries specified with the -l option until the end of the command line or until the
next -a option is encountered. Pass the -a option to the linker with the -Wx,args option.
Creating and Using Libraries 181