title: Calling GSL function inside a class in a shared library
body: <p>I'm trying make a shared library in c++ implementing tools for Fermi gases. I'm using the GSL library to solve a function numerically and my code runs without a problem without when running as a script, but when trying to convert it to a shared library and classes I encounter problems.</p>
  
  <p>I've seen similar questions:
  <a href="https://stackoverflow.com/questions/3194119/function-pointers-working-as-closures-in-c">Q1</a>
  <a href="https://stackoverflow.com/questions/13289311/c-function-pointers-with-c11-lambdas">Q2</a>
  <a href="https://stackoverflow.com/questions/13074756/how-to-avoid-static-member-function-when-using-gsl-with-c/18181494#18181494">Q3</a></p>
  
  <p>I'm fairly new to c++-programming and cannot seem to adapt the different answers to my problem. Probably since I do not quite understand the answers.</p>
  
  <p>My code is:</p>
  
  <pre><code>/* Define structure for the GSL-function: chempot_integrand */
  struct chempot_integrand_params { double mu; double T; };
  
  double
  ChemicalPotential::chempot_integrand (double x, void * params){
      /* Computes the integrand for the integral used to obtain the chemical potential.
       *
       * This is a GSL-function, which are integrated using gsl_integration_qag.
       */
  
      // Get input parameters.
      struct chempot_integrand_params * p = (struct chempot_integrand_params *) params;
      double mu = p-&gt;mu;
      double T = p-&gt;T;
  
      // Initiate output parameters for GSL-function.
      gsl_sf_result_e10 result;
      int status = gsl_sf_exp_e10_e( ( gsl_pow_2(x) - mu ) / T , &amp;result );
  
      if (status != GSL_SUCCESS){
          printf ("Fault in calculating exponential function.");
      }
  
      // Return (double) integrand.
      return (gsl_pow_2(x) / ( 1 + result.val * gsl_sf_pow_int(10,result.e10) ));
  }
  
  /* Define structure for the GSL-function: chempot_integration */
  struct chempot_integral_params { double T; };
  
  double
  ChemicalPotential::chempot_integration (double mu, double T){
      /* Computes the integral used to obtain the chemical potential using the integrand: chempot_integrand.
      */
  
      // Set input parameters for the integrand: chempot_integrand.
      struct chempot_integrand_params params_integrand = { mu, T };
  
      // Initiate the numerical integration.
      gsl_integration_workspace * w = gsl_integration_workspace_alloc (1000); // Allocate memory for the numerical integration. Can be made larger if neccessary, REMEMBER to change it in the function call: gsl_integration_qag as well.
      double result, error;
      gsl_function F;
      F.function = &amp;ChemicalPotential::chempot_integrand;
      F.params = &amp;params_integrand;
  
      // Upper limit for integration
      double TOL = 1e-9;
      double upp_lim = - T * gsl_sf_log(TOL) + 10;
  
      gsl_integration_qag (&amp;F, 0, upp_lim, 1e-12, 1e-12, 1000, 6, w, &amp;result, &amp;error);
  
      // Free memory used for the integration.
      gsl_integration_workspace_free (w);
  
      return result;
  }
  </code></pre>
  
  <p>and when compiling I get the error</p>
  
  <pre><code>error: cannot convert ‘double (Fermi_Gas::ChemicalPotential::*)(double, void*)’ to ‘double (*)(double, void*)’ 
  </code></pre>
  
  <p>in line</p>
  
  <pre><code>F.function = &amp;ChemicalPotential::chempot_integrand;
  </code></pre>