1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
int main (void)
{
void *handle, *vp;
char *error;
double (*cosine)(double);
handle = dlopen ("libm.so", RTLD_LAZY);
if (!handle) {
fprintf (stderr, "%s\n", dlerror());
exit(1);
}
vp = dlsym(handle, "cos");
if ((error = dlerror()) != NULL) {
fprintf (stderr, "%s\n", error);
exit(1);
}
memcpy (&cosine, &vp, sizeof cosine);
printf ("%f\n", (*cosine)(2.0));
dlclose(handle);
return EXIT_SUCCESS;
}
/* EOF */ |