1e1edcf7dSMichael Buch #include <cassert> 2e1edcf7dSMichael Buch #include <dlfcn.h> 3e1edcf7dSMichael Buch #include <string> 4e1edcf7dSMichael Buch 5e1edcf7dSMichael Buch extern struct Foo imported; 6e1edcf7dSMichael Buch main()7e1edcf7dSMichael Buchint main() { 8e1edcf7dSMichael Buch // LIB_NAME defined on commandline 9e1edcf7dSMichael Buch std::string libname{"./"}; 10e1edcf7dSMichael Buch libname += LIB_NAME; 11e1edcf7dSMichael Buch 12e1edcf7dSMichael Buch void *handle = dlopen(libname.c_str(), RTLD_NOW); 13e1edcf7dSMichael Buch struct Foo *foo = (struct Foo *)dlsym(handle, "global_foo"); 14e1edcf7dSMichael Buch assert(foo != nullptr); 15e1edcf7dSMichael Buch 16*e3116015SMichael Buch // Unload dylib (important on Linux so a program re-run loads 17*e3116015SMichael Buch // an updated version of the dylib and destroys the old lldb module). 18*e3116015SMichael Buch dlclose(handle); 19*e3116015SMichael Buch 20e1edcf7dSMichael Buch return 0; 21e1edcf7dSMichael Buch } 22