link

link — dynamic link

Calling sequence

link(files, sub-name)  
link(files, sub-name, flag)  
lst=link('show')  
// Link extensions for machines using ``dlopen''   
// (sun-solaris/linux-elf/alpha/hppa)  
x=link(files [, sub-names,flag]);  
link(x , sub-names [, flag]);  
ulink(x)  

Parameters

files : a character string or a vector of character strings. ld files used to define the new entry point (compiled routines, user libraries, system libraries,..)
sub-name : a character string. Name of the entry point in files to be linked.
sub-names : a character string or a vector of character strings . Name of the entry points in files to be linked.
x : an integer which gives the id of a shared library linked into Scilab with a previous call to link.
flag : character string 'f' or 'c' for Fortran (default) or C code.
names : a vector of character string. Names of dynamically linked entry points.

Description

link is a dynamic link facility: this command allows to add new compiled Fortran or C routines to Scilab executable code. Linked routines can be called interactively by the function fort. Linked routines can also be used as "external" for e.g. non linear problem solvers (ode, optim, intg, dassl...). Here are some examples:

The command link('foo.o','foo','f') links the Fortran object file foo.o with the entry point foo.

The command link('foo.o','foo','c') links the C object file foo.o with the entry point foo.

The command link('SCIDIR/libs/calelm.a','dcopy') links the Fortran routine dcopy in the library calelm.a.

A routine can be linked several times and can be unlinked with ulink. Note that, on some architectures (the ones on which ulink exists) when a routine is linked several times, all the version are kept inside Scilab.

Used with no arguments, link() returns the current linked routines.

If Scilab is compiled with static link (this is the default for SystemV machines) you may have to include the system libraries in the "link" command.

For example, if foo.o defines the object code of a routine named foo, you will use link in one the following way:



link('foo.o','foo').
link('foo.o -lm -lc','foo','c').
link('foo.o -lfor -lm -lc','foo').
link('foo.o -lftn -lm -lc','foo').
link('foo.o -L/opt/SUNWspro/SC3.0/lib/lib77 -lm -lc','foo')
   
    

If Scilab compiled with the "shared" option, the first example can be used even if a warning for unresolved references is issued.

(Experienced) users may also link a new Scilab interface routine to add a set of new functions. See Intersci documentation for interface generation and addinter function.

Remarks

IBM:For IBM-RS6000 only one program can be dynamically linked.
Demo:When running a demo, you may have some trouble with the link due to slight differences between systems. In this case, you modify the demo by adding the needed libraries in the link command.
dlopen:

For machines using dlopen functionality extended command can be used. a call to link returns an integer which gives the id of the shared library which is loaded into Scilab. This number can then be used as the first argument of the link function in order to link additional function from the linked shared library. The shared library is removed with the ulink command. for example to link functions f and g form binary file test.o the two following command can be used :



link('test.o',['f','g'])
   
        

or



x=link('test.o','f');
link(x,'g');
   
        

But



link('test.o','f');
link('test.o','g');
   
        

will also work but f and g will be loaded from two different shared libraries and won't be able to share data.

show:The command lst=link('show') will report information about linked shared libraries and linked functions. The return value of the function lst is 1 or 0. If the return value is 1 then the extended calling sequence described as Link extensions for machines using ``dlopen'' are accepted.
unlink :

(dlopen version) If the function f is changed and one wants to link the new version, it is necessary to use unlink to get rid of previous loaded versions of the function f



x=link('test.o','f');
// if I need to reload a new definition of f a call to unlink
// is necessary.
ulink(x);
link('test.o','f');
   
        
scilab symbols:

In order to load a symbol from the Scilab code on can use



link("Scilab",['Scilab-entry-point'])
   
        

This does not work on all architectures. On some machines, on can link a Scilab internal function after a first call to link ( with a default binary file )



link("test.o",['Scilab-entry-point'])
   
        

Note that with dld (Linux machine aout) you can use an empty string



link(" ",['Scilab-entry-point'])
   
        

See also

fort, c_link, addinter