-
Notifications
You must be signed in to change notification settings - Fork 0
/
main-hl.c
52 lines (46 loc) · 1.13 KB
/
main-hl.c
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <dlfcn.h>
#include "target-hl.h"
typedef struct {
void *handle;
Foo hot_foo;
} HotSO;
void loadFooFrom(HotSO *hso,char *libName)
{
if(hso->handle != NULL) {
if(dlclose(hso->handle)) {
fprintf(stderr, "Error: %s\n",dlerror());
}
hso->handle = NULL;
hso->hot_foo = NULL;
}
void *handle = dlopen (libName, RTLD_LAZY);
if(handle != NULL) {
Foo hot_foo = (Foo)dlsym (handle, "foo");
if(hot_foo != NULL) {
hso->handle = handle;
hso->hot_foo = hot_foo;
return;
} else {
fprintf(stderr, "Error: %s\n",dlerror());
}
dlclose(handle);
} else {
fprintf(stderr, "Error: %s\n",dlerror());
}
}
int main()
{
char buffer[4*1024];
HotSO hso = {0};
Foo hot_foo;
loadFooFrom(&hso, "./build/libtarget-dec.so");
hot_foo = hso.hot_foo;
hot_foo(17, 0.123, buffer);
printf("%s\n", buffer);
loadFooFrom(&hso, "./build/libtarget-bin.so");
hot_foo = hso.hot_foo;
hot_foo(17, 0.123, buffer);
printf("%s\n", buffer);
return 0;
}