-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.c
More file actions
33 lines (19 loc) · 720 Bytes
/
test.c
File metadata and controls
33 lines (19 loc) · 720 Bytes
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
#include <dlfcn.h>
#include <stdio.h>
typedef struct Point* (_make_point)( int x, int y);
typedef struct Point* (_free_point)(struct Point* p);
typedef double (_get_distance)( struct Point* a, struct Point* b);
int main(int argc, char *argv[]) {
void *myso = dlopen("./libpoints.dylib", RTLD_NOW);
_make_point *make_point = dlsym(myso, "make_point");
_free_point *free_point = dlsym(myso, "free_point");
_get_distance *get_distance = dlsym(myso, "get_distance");
struct Point* a = make_point(10,10);
struct Point* b = make_point(20,20);
double d = get_distance(a,b);
printf("distance: %f\n", d);
free_point(a);
free_point(b);
dlclose(myso);
return 0;
}