*/
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
Note that the
Output of testlib2
$ cc
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
•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