SDL2 example
[mirrors/Programs.git] / c / cshell / cshell.c
CommitLineData
21c4e167
H
1#include <stdio.h>
2#include <dlfcn.h>
3
4typedef int (*func)(int, int);
5func add, sub, mul, div;
6
7int main()
8{
9 int a = 5, b = 4;
10 void *arithHandle = NULL;
11
12 arithHandle = dlopen("libarithmetic.so", RTLD_NOW);
13 if ( NULL == arithHandle )
14 {
15 printf("Arithmetic library cant be opened\n");
16 }
17
18 add = (func) dlsym (arithHandle, "add");
19 sub = (func) dlsym (arithHandle, "sub");
20 mul = (func) dlsym (arithHandle, "mul");
21 div = (func) dlsym (arithHandle, "div");
22
23 printf("Add :: %d\n", add(a, b));
24 printf("Sub :: %d\n", sub(a, b));
25 printf("Mul :: %d\n", mul(a, b));
26 printf("Div :: %d\n", div(a, b));
27
28 dlclose(arithHandle); //Its important to call dlclose() when you are done
29 return 0;
30}
This page took 0.153913 seconds and 4 git commands to generate.