/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
#include<dlfcn.h>
#include<math.h> 

void chcallfuncbynamev() {

  void *dlhandle, *fptr;

  dlhandle = dlopen("libch.dl", RTLD_LAZY);
  if(dlhandle == NULL) {
    printf("Error: %s(): dlopen(): %s\n", __func__, dlerror());
    return;
  }

  fptr = dlsym(dlhandle, "chcallfuncbynamev_chdl");
  if(fptr == NULL) {
    printf("Error: %s(): dlsym(): %s\n", __func__, dlerror());
    return;
  }

  dlrunfun(fptr, NULL, chcallfuncbynamev);

  if(dlclose(dlhandle)!=0) {
    printf("Error: %s(): dlclose(): %s\n", __func__, dlerror());
    return;
  }

  return;
}

/* this function will be called from a C function */
int chfun(int arg1) {
  printf("in the Ch function chfun(), arg1 = %d\n", arg1);
  return arg1 * arg1;
}

int main() {
  chcallfuncbynamev();
  return 0;
}
