-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibdemo.c
42 lines (36 loc) · 823 Bytes
/
libdemo.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
/* libdemo.c - demo for importing libnewlisp.so
*
* compile using:
* gcc -ldl libdemo.c -o libdemo && ./libdemo '(+ 3 4)'
*
* use:
*
* ./libdemo '(+ 3 4)'
* ./libdemo '(symbols)'
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
int main(int argc, char * argv[])
{
void * hLibrary;
char * result;
char * (*func)(char *);
char * error;
if((hLibrary = dlopen("/usr/local/lib/libnewlisp.so",
RTLD_GLOBAL | RTLD_LAZY)) == 0)
{
printf("%s\n", dlerror());
exit(-1);
}
func = dlsym(hLibrary, "newlispEvalStr");
if((error = dlerror()) != NULL)
{
printf("error: %s\n", error);
exit(-1);
}
printf("%s\n", (*func)(argv[1]));
dlclose(hLibrary);
return(0);
}