// foo.c // represents the XS lib referencing a symbol (lgamma) in an external library libm.so #include double foo() { return lgamma(42.0); } // mytest.c // this is just a wrapper which essentially does what perl/DynaLoader is doing, // i.e. loading the XS lib (Foo.so) dynamically at runtime #include #include #include int main() { double (*foo)(void); char *error; printf("dynamically loading 'Foo.so'...\n"); void *so = dlopen("Foo.so", RTLD_LAZY); if (!so) { fprintf(stderr, "%s\n", dlerror()); exit(1); } dlerror(); *(void **) (&foo) = dlsym(so, "foo"); if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(1); } printf("%f\n", (*foo)()); dlclose(so); exit(0); }