/* * example.c * * gcc example.c -o example -ldl */ #include #include #include #include #include typedef int (* FDMS1_HW_INIT)(libusb_device_handle *); int main(int argc, char **argv) { char dll_name[128]; void *dll_handle; FDMS1_HW_INIT init; /* Given a choice made by the user * (in this case a string like 192k from cmd * */ if (argc != 2) { printf("Usage: %s [192k|384k|768k|1536k]\n\n",argv[0]); exit(0); } /* some basic check */ if (strlen(argv[1]) > 5) { printf("Invalid parameter\n\n"); exit(1); } /* Build the so name, for example using sprintf() */ sprintf(dll_name,"/home/nando/Source/fdm/libfdms1_hw_init_%s.so.1.0", argv[1]); /* Now load the dll (the dll must be in a sys path or full * path name must be given) */ dll_handle = dlopen(dll_name, RTLD_NOW); if (dll_handle == NULL) { printf("%s\n\n",dlerror()); exit(1); } /* get the pointer to the init function * Remember to downcast to the real function pointer because * dlsym returns a generic void* */ init = (FDMS1_HW_INIT) dlsym(dll_handle,(const char *)"fdms1_hw_init"); if (init == NULL) { printf("Function not found in library\n\n"); } else { /* Call the init... but do not expect that works...*/ libusb_device_handle *usb_handle = NULL; init(usb_handle); } /* cleanup */ dlclose(dll_handle); }