Listing 3: ex1lnx.cpp, C++ test file on Linux.

// ex1lnx.cpp  —  Test file for passing a single 
// real argument to a F77 function in a dll
#include <iostream>
#include <dlfcn.h>
int main()
{
    void *hDll = dlopen("./ex1.so", RTLD_NOW);
    typedef float (* LPFNDLLFUNC)(float&);
    LPFNDLLFUNC lpFunc = NULL;
    lpFunc = (LPFNDLLFUNC)dlsym(hDll, "foo_");
    float x = 1.2f;
    float y = 0.0f;
    y = lpFunc(x);
    std::cout << "y = foo(" << x << ") = " 
              << y << std::endl;
    dlclose(hDll);
    return 0;
}