Listing 12: ex4lnx.cpp, C++ file on Linux.
// ex4lnx.cpp Test file for passing a function pointer to an // F77 function in a dll #include <iostream> #include <dlfcn.h> float foo(float &x) { return x * 2.0f; } int main() { void *hDll = dlopen("./ex4.so", RTLD_NOW); typedef float (*pMyFunc)(float&); typedef float (* LPFNDLLFUNC)(pMyFunc, float&); LPFNDLLFUNC lpFunc = NULL; lpFunc = (LPFNDLLFUNC)dlsym(hDll, "myeval_"); float x,y; pMyFunc pfunc = (pMyFunc) foo; x = 1.2f; y = lpFunc(pfunc, x); std::cout << "foo( " << x << " ) " << " = " << y << std::endl; dlclose(hDll); return 0; }