#include <stdio.h>
#include <dlfcn.h>

#define X 2
#define Y 3

int debug = 1;

int main() 
{
    void *handle;
    int (*add)(int, int);
    char *error;
    int sum;

    /* dynamically load shared library that contains add() */
    handle = dlopen("./kernels.so", RTLD_LAZY);
    if (!handle) {
	fprintf(stderr, "%s\n", dlerror());
	exit(1);
    }

    /* get a pointer to the add() function we just loaded */
    add = dlsym(handle, "add");
    if ((error = dlerror()) != NULL) {
	fprintf(stderr, "%s\n", error);
	exit(1);
    }

    /* Now we can call add just like any other function */
    sum = add(X, Y);

    return 0;
}
