#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <gnu/lib-names.h>
int main() {
void *handle = NULL;
double (*cosine)(double) = NULL;
char *error = NULL;
printf("%s\n", LIBM_SO);
handle = dlopen(LIBM_SO, RTLD_LAZY);
if(!handle){
fputs(dlerror(), stderr);
exit(1);
}
dlerror(); // clear error info;
cosine = dlsym(handle, "cos");
if((error = dlerror()) != NULL){
fputs(error, stderr);
exit(1);
}
printf("%f\n", (*cosine)(2.0));
dlclose(handle);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: