Hi all,
I’m facing the situation where I need to interface function in a shared library dll file (coolprop.org), originally written in C++, like these
EXPORT_CODE void CONVENTION PropsSImulti(const char* Outputs, const char* Name1, double* Prop1, const long size_Prop1, const char* Name2,
double* Prop2, const long size_Prop2, char* backend, const char* FluidNames, const double* fractions,
const long length_fractions, double* result, long* resdim1, long* resdim2);
Is there some documentation, examples of other gateways, where I could find how to write wrapper for such situation ?
Indeed, in toolbox_skeleton is shown among others how to build automatically the toolbox from the user’s source in cpp, but the case of existing thirdparty shared dll with header file .h without source files is not illustrated. I’d like to start a minimal wrapper writing it for just one function like these .
Also in Getting started with API_Scilab is explained the key mechanisms for one single function, but in C not C++, and building loader.sce from source .c, not thirdparty shared dll case , hence no illustration how to load the third party dll.
Thank you for advising, pointing a public c++ gateway toolbox to cpp shared library dll to mimic, …
David
Hi David,
From my understanding, you only need a few functions without datatype conversion (eg. library type to Scilab datatype) but only data wrapping using a well defined calling convention : (double* Prop1, const long size_Prop1) for an input vector, (double* result, long* resdim1, long* resdim2) for an output matrix.
This is the perfect use case for SWIG ; this interface generator will convert an interface file written in pseudo C-code into Scilab C API code.
I used it in scilab / forge / fmu-wrapper · GitLab ; you can take a look in the SWIG src/c/*.i files. The loader decode the xml generated file to link into Scilab.
Thank you David for pointing this approach with SWIG, I’ll give an attempt to automate the generation of wrapping code from the coolprop.h and coolprop.dll. If i understand it well, with specific configuration of SWIG for Scilab target, it generates automatically the wrapper files: .cpp .hxx and builder.sce and loader.sce instead of writing by hand.
remark: The help page for scilab in SWIG may be updated along the evolution of Scilab since version 5.5 ~10 years , especially with regard to new Scilab_API since scilab6 and classes objects recent introduction, links pointing to current Scilab (documentation, code repository) .
Hi David,
You are correct about the SWIG wrapper, it will generate all for you at first.
If you need to create a proper toolbox (with demos, help files, and so on), you will need some files from Scilab skeleton toolbox around the generated ones.
About the documentation, the generated C API is compatible with Scilab 5 and 6. The port to the new C API is not done, feel free to contribute
.