Listing 14: ex5lnx.cpp, C++ file on Linux.
// ex5lnx.cpp Test file for calling Muller's method from an F77 dll
#include <iostream>
#include <complex>
#include <cmath>
#include <dlfcn.h>
using namespace std;
complex<double> myFunc(complex<double> &x)
{
complex<double> temp;
temp = pow(x - complex<double>(1.0f, 0.0f),
complex<double> (10.0f, 0.0f));
return temp;
}
int main()
{
void *hDll = dlopen("./muller.so", RTLD_NOW);
typedef complex<double> (*pFunc) (complex<double>&);
typedef void (* LPFNDLLFUNC)(pFunc, double&,
int&, int&, int&, int&, complex<double>*,int&, int*,int&);
LPFNDLLFUNC lpFunc = NULL;
lpFunc = (LPFNDLLFUNC)dlsym(hDll, "muller_");
pFunc pf = (pFunc) myFunc;
double eps = 1.0e-10;
int nsig, kn, nguess, n, itmax, ier;
nsig = 20;
kn=0;
nguess = 0;
n = 10;
itmax = 2000;
ier = 0;
int infer[10] = {0};
complex<double> *x;
x = new complex<double> [n];
int i;
for (i=0; i<n; i++)
{
x[i] = complex<double> (0.0f, 0.0f);
}
lpFunc(pf, eps, nsig, kn, nguess, n, x, itmax, infer, ier);
for (i=0; i<n; i++)
{
std::cout << "x[" << i << "] = " << x[i]
<< ", iteration no. is "
<< infer[i] << std::endl;
}
delete [] x;
dlclose(hDll);
return 0;
}