0

I would like to modify a c++ script using the "dlopen" and "dlclose" functions for windows.

I tried to go through the dlfcn-win32 library but during the compilation the "dlopen" and "dlclose" functions were not found.

below is the script in question :

#include "cantera/kinetics/CustomKinetics.h"

#include <iostream>
#include <dlfcn.h>
 
using namespace std;

namespace Cantera 
{
  CustomKinetics::CustomKinetics(thermo_t* th) : GasKinetics(th) 
  {
    printf("WARNING: Using customized kinetics from f90 file.\n");
    handle = dlopen("customkinetics.so", RTLD_LAZY);

    // load symbol 
    ck = (ck_t) dlsym(handle, "customkinetics_");

  }

  void CustomKinetics::get_wdot_reduced(doublereal* wdot)
  {

    doublereal P = thermo().pressure();
    doublereal T = thermo().temperature();
    // New yarc2 format
    //doublereal rho = thermo().density();
    const doublereal* m_y = thermo().massFractions();

    ck(&P,&T,&m_y[0],&wdot[0]);

    // New yarc2 format
    //ck(&P,&T,&rho,&m_y[0],&wdot[0]);

    // Old yarc format
    //mol/kmol conversion cantera is in kmol
    for (size_t i=0;i<thermo().nSpecies();i++) {
        wdot[i]=wdot[i]/1000.0;
    }
  }

  void CustomKinetics::close_dl()
  {
   dlclose(handle);
  }

}

How can I modify this script to be compatible with the mingw64 libraries? Could you give me an example?

Thank you in advance for your help,

Pierre.

Pgr
  • 1
  • FWIW, the rough equivalent of `dlopen` on Windows is `LoadLibrary`, `dlsym` -> `GetProcAddress`, `dlclose` -> `FreeLibrary`. – 500 - Internal Server Error Apr 08 '22 at 12:29
  • `dlsym` works on C functions, so you can use the existing C answer. You can't load a whole class that way, but `GetProcAddress` has the same restrictions so it's not a portability problem. – MSalters Apr 08 '22 at 12:54

0 Answers0