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

Advanced Shared Library Features
This section explains additional things you can perform with shared libraries. It discusses
the following topics:
Forcing the Export of Symbols in main
Binding Times
Side Effects of C++ Shared Libraries
Routines and Options to Manage C++ Shared Libraries
Version Control for Shared Libraries
Adding New Versions to a Shared Library
Forcing the Export of Symbols in main
By default, the linker exports from a program only those symbols that were imported by
a shared library. For example, if shared libraries of an executable does not reference
the main routine of the program, the linker does not include the main symbol in the
export list of a.out.
Normally, this is a problem only when a program explicitly calls shared library
management routines. (See “Routines and Options to Manage C++ Shared Libraries
(page 229).)
To make the linker export all symbols from a program, use the -Wl,-E option, which
passes the -E option to the linker.
Binding Times
Because shared library routines and data are not actually contained in the a.out file,
the dynamic loader must attach the routines and data to the program at run time. To
accelerate program startup time, routines in a shared library are not bound until
referenced. (Data items are always bound at program startup.) This deferred binding
distributes binding overhead across the total execution time of the program and is
especially helpful for programs that contain many references that are not likely to be
executed.
Forcing Immediate Binding
You can force immediate binding, that forces all routines and data to be bound at startup
time. With immediate binding, the overhead of binding occurs only at program startup
time, rather than across the execution of the program. Immediate binding also detects
unresolved symbols at startup time, rather than during program execution. Immediate
binding provides better interactive performance, but the program startup time is longer.
To force immediate binding, use the option -Wl,-B,immediate.
Example:
aCC -Wl,-B,immediate draw_shapes.o -lshape
228 Tools and Libraries