-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcall_main.c
More file actions
35 lines (27 loc) · 735 Bytes
/
Copy pathcall_main.c
File metadata and controls
35 lines (27 loc) · 735 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
34
35
#include <stdio.h>
#include <dlfcn.h>
#define DLL_FILE_NAME "libcac.so"
int main()
{
void *handle;
int (*func)(int, int);
char *error;
int a = 30;
int b = 5;
handle = dlopen(DLL_FILE_NAME, RTLD_NOW);
if (handle == NULL)
{
fprintf(stderr, "Failed to open libaray %s error:%s\n", DLL_FILE_NAME, dlerror());
return -1;
}
func = dlsym(handle, "add");
printf("%d + %d = %d\n", a, b, func(a, b));
func = dlsym(handle, "sub");
printf("%d + %d = %d\n", a, b, func(a, b));
func = dlsym(handle, "div");
printf("%d + %d = %d\n", a, b, func(a, b));
func = dlsym(handle, "mul");
printf("%d + %d = %d\n", a, b, func(a, b));
dlclose(handle);
return 0;
}