Difference between revisions of "Dlopen code example"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
void loadPlugins( const char *path ) { | void loadPlugins( const char *path ) { | ||
#ifndef LL_WINDOWS | #ifndef LL_WINDOWS | ||
int (*slp_plugin_init)(plugin_interface *); | int (*slp_plugin_init)(plugin_interface *); | ||
Latest revision as of 19:22, 12 February 2007
void loadPlugins( const char *path ) { #ifndef LL_WINDOWS int (*slp_plugin_init)(plugin_interface *); DIR * plugindir; struct dirent * mydirent; void * dlhandle; char plugin_name[FILENAME_MAX]; plugindir = opendir( path ); if( NULL == plugindir ) { llwarns << "Could not open plugins directory: " << path << llendl; return; } while (mydirent = readdir(plugindir)) { if(!strcasestr(mydirent->d_name, PLUGINEXT)) { fprintf(stderr, "Ignoring non-plugin directory entry %s\n", mydirent->d_name); continue; } snprintf(plugin_name, sizeof(plugin_name), "%s%s%s", path, gDirUtilp->getDirDelimiter().c_str(), mydirent->d_name); fprintf(stderr, "Trying to load plugin: %s\n", plugin_name); dlhandle = dlopen(plugin_name, RTLD_LAZY); if (dlhandle==NULL) { fprintf(stderr,"Error opening %s: %s\n", plugin_name, dlerror()); continue; } slp_plugin_init = (int(*)(plugin_interface*))dlsym(dlhandle, "initOSLPlugin"); if (!slp_plugin_init) { fprintf(stderr,"Error looking up initOSLPlugin: %s\n", dlerror()); dlclose(dlhandle); continue; } slp_plugin_init(&gPluginInterface); //char * (*getName)(void) = (char *(*)())dlsym(*(itPlugins), "getPluginName" ); //vPlugins[ getName() vPlugins->push_back( dlhandle ); } #endif }