dlopen 加载so库
#include <stdio.h>
#include <dlfcn.h>
int main(int argc, char **argv) {
void *handle;
double (*cosine)(double);
char *error;
handle = dlopen ("/tmp/libtest.so", RTLD_LAZY);
if (!handle) {
fprintf (stderr, "%s ", dlerror());
exit(1);
}
cosine = (double(*)(double))dlsym(handle, "cos");
if ((error = dlerror()) != NULL) {
fprintf (stderr, "%s ", error);
exit(1);
}
printf ("%f ", (*cosine)(2.0));
dlclose(handle);
return 0;
}
浙公网安备 33010602011771号