brintos

brintos / llvm-project-archived public Read only

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