-
Notifications
You must be signed in to change notification settings - Fork 4
/
use_so11.c
48 lines (41 loc) · 1.12 KB
/
use_so11.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
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
#include "so11.h"
int main()
{
void *library;
double (*length)(struct Vector v);
/* pokus o otevreni a nacteni sdilene knihovny */
library = dlopen("./so11.so", RTLD_LAZY);
if (library != NULL) {
printf("dynamic library loaded: %p\n", library);
} else {
puts("unable to load dynamic library");
return 1;
}
length = dlsym(library, "length");
if (length != NULL) {
struct Vector v;
v.X = 1.0;
v.Y = 1.0;
double ret;
printf("address for 'length' retrieved: %p\n", (void*)length);
puts("Calling 'length'...");
ret = length(v);
printf("...called, vector length: %f\n", ret);
} else {
puts("unable to retrieve address for 'length'");
}
/* pokus o uzavreni sdilene knihovny */
if (library != NULL) {
int err = dlclose(library);
if (err != 0) {
puts("unable to close dynamic library");
return 1;
} else {
puts("dynamic library closed");
}
}
return EXIT_SUCCESS;
}