1 /* $OpenBSD: prog.c,v 1.2 2013/10/28 08:40:05 jsg Exp $ */ 2 /* Public Domain, 2008, Matthieu Herrb */ 3 4 #include <dlfcn.h> 5 #include <stdio.h> 6 #include <stdlib.h> 7 8 void *handle = NULL; 9 10 typedef int (*foofunc)(void); 11 12 int 13 main(int argc, char *argv[]) 14 { 15 foofunc foo; 16 int i; 17 18 printf("loading: %s\n", FOO); 19 handle = dlopen(FOO, RTLD_LAZY|RTLD_GLOBAL); 20 if (handle == NULL) { 21 errx(1, "dlopen: %s: %s\n", FOO, dlerror()); 22 } 23 printf("loaded: %s\n", FOO); 24 printf("looking up foo\n"); 25 foo = (foofunc)dlsym(handle, "foo"); 26 printf("found %p - calling it\n", foo); 27 i = foo(); 28 printf("done.\n"); 29 exit(i); 30 } 31