/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
#include <dlfcn.h>
double func1(double x) {
    void *chSample_handle;
    void *fptr;
    double retval;

    chSample_handle = dlopen("libsample.dl", RTLD_LAZY);
    if(chSample_handle == NULL) {
        fprintf(_stderr, "Error: dlopen(): %s\n", dlerror());
        fprintf(_stderr, "cannot get chSample_handle in sample.h\n");
        exit(-1);
    }

    fptr = dlsym(chSample_handle, "func1_chdl");
    if(fptr == NULL) {
        fprintf(_stderr, 
                  "Error: %s(): dlsym(): %s\n", __func__, dlerror());
        return NaN;
    }

    dlrunfun(fptr, &retval, func1, x);

    dlclose(chSample_handle);
    return retval;
}
