Created
December 10, 2008 09:44
-
-
Save hernad/34291 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gcc -rdynamic -o dlopen_e1 dlopen_e1 -ldl | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <dlfcn.h> | |
int main(int argc, char **argv) { | |
void *handle; | |
double (*cosine)(double); | |
char *error; | |
handle = dlopen ("libm.so", RTLD_LAZY); | |
if (!handle) { | |
fprintf (stderr, "%s\n", dlerror()); | |
exit(1); | |
} | |
dlerror(); /* Clear any existing error */ | |
cosine = dlsym(handle, "cos"); | |
if ((error = dlerror()) != NULL) { | |
fprintf (stderr, "%s\n", error); | |
exit(1); | |
} | |
printf ("%f\n", (*cosine)(2.0)); | |
dlclose(handle); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment