6.2.2.1 Static library

In the directory SCIDIR/examples/interface-tutorial just enter the make command in an Unix platform or in the Windows environment with the Visual C++ environment enter nmake /f Makefile.mak. This command produces the following file tutorial_gateway.c which is a C function produced by the Makefile :

#include "mex.h" 
extern Gatefunc intview;
extern Gatefunc intmatmul;
 
static GenericTable Tab[]={
{(Myinterfun)sci_gateway, intview,"error msg"},
{(Myinterfun)sci_gateway, intmatmul,"error msg"},
         };

int C2F(tutorial_gateway)()
{  Rhs = Max(0, Rhs);
(*(Tab[Fin-1].f))(Tab[Fin-1].name,Tab[Fin-1].F);
  return 0;
}
This function is essentially the table of C functions which are dynamically linked wih Scilab.

The following file tutorial.sce is also produced by the Makefile :

scilab_functions =[...
"view";
"matmul";
           ];
auxiliary="";
files=G_make(["tutorial_gateway.o","tutorial.a", auxiliary],"void(Win)");
addinter(files,"tutorial_gateway",scilab_functions);

The Scilab function addinter makes the correspondance between the C gateway functions (such as intmatmul) and their names as Scilab functions.

To load the newly created function matmul, one has to execute this script and then the function matmul can be called into Scilab

-->exec tutorial.sce

-->A=rand(2,3);B=rand(3,3);C=matmul(A,B);   //C=A*B

Summing up, to build an static interface, the user has to write a gateway function such as intmatmul. Then he has to edit the Makefile in SCIDIR/examples/interface-tutorial (or a copy of it) and to put there the name of his gateway function(s) (e.g. intmatmul.o) in the target CINTERFACE and the name of the corresponding Scilab function (e.g. matmul) in the target CFUNCTIONS with the same ordering. Typing make produces the static library and a script file (here tutorial.sce) which should be executed each time the newly created function(s) are needed. Of course, it is possible to perform this operation automatically when Scilab is launched by creating a startup file .scilab identical to tutorial.sce.