HP-UX Linker and Libraries User's Guide

*/
printf("1.0in = %5.2fcm\n", (*in_to_cm)(1.0));
printf("1.0gal = %5.2fl\n", (*gal_to_l)(1.0));
printf("1.0oz = %5.2fg\n", (*oz_to_g)(1.0));
/*
* Call routines from libtwo.so:
*/
(*foo)();
(*bar)();
/*
* Unload the libraries so we can see messages displayed by initializer:
*/
shl_unload(hndl_units);
shl_unload(hndl_two);
}
Following is the command to create the executable testlib2:
$ cc -Aa -Wl,-E -o testlib2 testlib2.c init.c -ldld
Note that the -Wl,-E option is required to cause the linker to export all symbols from the main
program. This allows the shared libraries to find the _INITIALIZER function in the main executable.
The output from running testlib2 is given below:
Output of testlib2
$ cc -Aa testlib2.c -o testlib2 -ldld
$ testlib2
libunits.so loaded
libtwo.so loaded
1.0in = 2.54cm
1.0gal = 3.79l
1.0oz = 28.35g
foo called
bar called
libunits.so unloaded
libtwo.so unloaded
The dlopen Shared Library Management Routines
This section describes the dl* family of shared library management routines. All these routines are
available in IPF/PA-64 mode. Support for the following routines is available in PA-32 mode:
dlopen
dlclose
dlsym
dlerror
The dlopen Routine
The dlopen routine opens a shared library.
Syntax
void *dlopen(const char *file, int mode);
void *dlopene(const char *file, int mode, struct dlopen_opts *opts);
148 Shared Library Management Routines