Listing 9: ex3lnx.cpp, C++ file on Linux.
// ex3lnx.cpp Test file for passing arrays to an F77 function in a dll
#include <iostream>
#include <dlfcn.h>
int main()
{
void *hDll = dlopen("./ex3.so", RTLD_NOW);
typedef void (* LPFNDLLFUNC) (float*, float*, float*, int&);
LPFNDLLFUNC lpFunc = NULL;
lpFunc = (LPFNDLLFUNC)dlsym(hDll, "dot_");
int i, numPts = 10;
float x[10], y[10], z[10];
for( i=0; i<numPts; i++ )
{
x[i] = 1.0f * i;
y[i] = 2.0f * i;
z[i] = 0.0f;
}
lpFunc(x, y, z, numPts);
for( i=0; i<numPts; i++ )
{
std::cout << "z[" << i << "] = "
<< x[i] << " * "
<< y[i] << " = "
<< z[i] << std::endl;
}
dlclose(hDll);
return 0;
}