Skip to content

Instantly share code, notes, and snippets.

@fivunlm
Last active March 8, 2018 11:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fivunlm/96a1a0ab5fb5f1fc357c85d2214ddf7a to your computer and use it in GitHub Desktop.
Save fivunlm/96a1a0ab5fb5f1fc357c85d2214ddf7a to your computer and use it in GitHub Desktop.
#include <iostream>
#include <dlfcn.h>
int main() {
using std::cout;
using std::cerr;
cout << "C++ dlopen demo\n\n";
// open the library
cout << "Opening hello.so...\n";
void* handle = dlopen("<<PATH_TO_.SO>>", RTLD_NOW);
if (!handle) {
cerr << "Cannot open library: "<< dlerror() << '\n';
return 1;
}
// close the library
cout << "Closing library...\n";
dlclose(handle);
}
// g++ main.cpp -ldl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment