Skip to content

Instantly share code, notes, and snippets.

@deoxxa
Created December 16, 2010 08:08
Show Gist options
  • Save deoxxa/743188 to your computer and use it in GitHub Desktop.
Save deoxxa/743188 to your computer and use it in GitHub Desktop.
int load_plugin(char* location)
{
void *lhandle = NULL;
void (*fhandle)() = NULL;
std::cout << "Loading plugin " << location << "\n";
lhandle = dlopen(location, RTLD_LAZY);
if (lhandle == NULL)
{
std::cout << "Could not load " << location << "\n";
return 1;
}
fhandle = (void (*)()) dlsym(lhandle, "init");
if (fhandle == NULL)
{
std::cout << "Could not get function handle\n";
return 2;
}
fhandle();
dlclose(lhandle);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment