6.2.2.2 Dynamic library

The directory SCIDIR/examples/interface-tutorial-so contains the material necessary to create a dynamic library (or a dll in the Windows environment) that can be dynamically linked with Scilab. This directory contains the following file called builder.sce :
// This is the builder.sce 
// must be run from this directory 

ilib_name  = "libtutorial"           // interface library name 
files = ["intview.o","intmatmul.o"]  // objects files 
                                     // 
libs  = []                           // other libs needed for linking
table = [ "view", "intview";         // table of (scilab_name,interface-name)
          "matmul","intmatmul"];     //

// do not modify below 
// ----------------------------------------------
ilib_build(ilib_name,table,files,libs)
The user should edit this file, which is a Scilab script, and in particular the variables files (a row vector of strings) anf table a two column matrix of strings. files should contain the names of all the object files (gateway functions and C functions called). Each row of table is a pair of two strings: the first is the name of the Scilab function, and the second the name of the gateway function. Here we have two functions view which has intview as gateway and matmul which has intmatmul as gateway. This is the example given above. After the file builder.sce has been edited, it should be executed in Scilab by the command
-->exec builder.sce
Scilab then generates the file loader.sce :
// generated by builder.sce
libtutorial_path=get_file_path('loader.sce');
functions=[ 'view';
            'matmul';
];
addinter(libtutorial_path+'/libtutorial.so','libtutorial',functions);
This file should be executed in Scilab to load the newly created function matmul
-->exec loader.sce

-->A=rand(2,3);B=rand(3,3);C=matmul(A,B);   //C=A*B
Summing up, to build a dynamic interface the user has to write a gateway function (such as intmatmul), then he has to edit the file builder.sce (or a copy of it) to enter the name of the Scilab function and the necessary C functions, then he has to execute the script builder.sce. This produce the dynamic library and the script loader.sce. Then each time he needs the newly created function(s), he has to execute the script loader.sce.