~tim/dlopen_test

dlopen_test/main.c -rw-r--r-- 468 bytes View raw
c647d1a7Tim Morgan Add unlicense 1 year, 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <dlfcn.h>
#include <stdio.h>
#include <unistd.h>

int main() {
  while(1) {
    void* lib_handle = dlopen("./lib.so", RTLD_NOW | RTLD_GLOBAL);

    if (lib_handle == NULL) {
      printf("Failed loading lib\n");
    } else {
      printf("Loaded lib successfully\n");

      void (*lib_func)() = dlsym(lib_handle, "lib_func");
      lib_func();

      dlclose(lib_handle);
    }

    sleep(5);
    printf("----------------------------\n");
  }

  return 0;
}