# Compile and run with Call Scilab

How to compile a native application based on or using Scilab

## Compilation

To compile a native code based on Call Scilab, it is necessary to define some arguments, variables and paths.

- CFLAGS. Call Scilab needs to have access to the headers of Scilab core and call Scilab module.

  - Linux/Unix/MacOSX:

    - In the binary version of Scilab, CFLAGS must be set to /path/to/scilab/include/scilab/core/ and /path/to/scilab/include/scilab/call_scilab/

    - In the source tree of Scilab, CFLAGS must be set to /path/to/scilab/modules/core/includes/ and /path/to/scilab/modules/call_scilab/includes/

  - Windows

- LD_LIBRARY_PATH - Paths to libscilab.so and libjavasci.so (or .dll, .jnilib...)

  - Linux/Unix/MacOSX:

    - In the binary version of Scilab, SCI will point to /path/to/scilab/lib/scilab/

    - In the source tree of Scilab, SCI will point to the root of the source tree /path/to/scilab/modules/call_scilab/.libs/ and /path/to/scilab/.libs/

- LDFLAGS - The name of the library to link against

  - Linux/Unix/MacOSX: It is only mandatory to link against scilab. This should include the other libraries.

The following example is a Makefile to build against Scilab binary

    # A sample Makefile building a C code using Call Scilab using Scilab binary
    PATH_SCILAB = /path/to/scilab/
    # Note that PATH_SCILAB can be /usr/ is using a packaged version of Scilab.
    SCILAB_CFLAGS = -I$(PATH_SCILAB)/include/scilab/
    SCILAB_LDFLAGS = -lscilab
    PATH_TO_LIB_SCILAB = $(PATH_SCILAB)/lib/scilab/
    PATH_TO_LIB_CALL_SCILAB = $(PATH_SCILAB)/lib/scilab/

    all: simple_call_scilab.c
    	export LD_LIBRARY_PATH=$(PATH_TO_LIB_SCILAB):$(PATH_TO_LIB_CALL_SCILAB)
    	gcc -o myExample $(SCILAB_LDFLAGS) -L$(PATH_TO_LIB_SCILAB) -L$(PATH_TO_LIB_CALL_SCILAB) $(SCILAB_CFLAGS) simple_call_scilab.c

The following example is a Makefile to build against Scilab source tree

    # A sample Makefile building a C code using Call Scilab using Scilab built in it source tree.
    PATH_SCILAB = /path/to/scilab/sources/
    SCILAB_CFLAGS = -I$(PATH_SCILAB)/modules/core/includes/ -I$(PATH_SCILAB)/modules/call_scilab/includes/
    SCILAB_LDFLAGS = -lscilab
    PATH_TO_LIB_SCILAB = $(PATH_SCILAB)/modules/.libs/
    PATH_TO_LIB_CALL_SCILAB = $(PATH_SCILAB)/modules/call_scilab/.libs/

    all: simple_call_scilab.c
    	export LD_LIBRARY_PATH=$(PATH_TO_LIB_SCILAB):$(PATH_TO_LIB_CALL_SCILAB)
    	gcc -o myExample $(SCILAB_LDFLAGS) -L$(PATH_TO_LIB_SCILAB) -L$(PATH_TO_LIB_CALL_SCILAB) $(SCILAB_CFLAGS) simple_call_scilab.c

## Running

To run an application based on Call Scilab, there are a few other things to set up.

Some global variables must me set:

- SCI - Path to Scilab files

  - Linux/Unix/MacOSX:

    - In the binary version of Scilab, SCI will point to /path/to/scilab/share/scilab/

    - In the source tree of Scilab, SCI will point to the root of the source tree /path/to/scilab/source/tree/

  - Windows:

- LD_LIBRARY_PATH - Paths to libscilab.so and libjavasci.so (or .dll, .jnilib...)

  - Linux/Unix/MacOSX:

    - In the binary version of Scilab, SCI will point to /path/to/scilab/lib/scilab/

    - In the source tree of Scilab, SCI will point to the root of the source tree /path/to/scilab/modules/javasci/.libs/ and /path/to/scilab/.libs/

- LD_LIBRARY_PATH (Java) - Paths to Java native libraries (libjava.so, libjvm.so, libhpi.so)... It is usually provided by the operating system or by Scilab distribution. Please note that won't be necessary in Scilab 5.2

  - Linux/Unix:

    - JAVA_HOME/jre/lib/<arch>/, JAVA_HOME/jre/lib/<arch>/server, JAVA_HOME/jre/lib/<arch>/native_threads/ (<arch> can be i386, etc...)

  - Mac OS X:

  - Windows

Note that two environnement variables are taken in account for specific needs:

- `SCI_DISABLE_TK=1` Disables Tk (Tcl's GUI)

- `SCI_JAVA_ENABLE_HEADLESS=1` Launch Java in headless mode (no AWT/Swing)

## Examples

    # Serie of declarations to execute my binary.

    # With a Scilab source tree:
    $ SCI=<path to Scilab source tree>
    $ export LD_LIBRARY_PATH=$SCI/modules/.libs/:$SCI/modules/call_scilab/.libs/:$SCI/modules/api_scilab/.libs

    # With a Scilab binary:
    $ SCI_PATH=<path to Scilab binary>
    $ export LD_LIBRARY_PATH=$SCI_PATH/lib/scilab/

    # Set the path to Java Virtual Machine library; This is mandatory for graphics features
    # Don't forget to update arch (i386) and paths to whatever is necessary
    $ export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/
    $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JAVA_HOME/jre/lib/i386/:$JAVA_HOME/jre/lib/i386/server/
    $ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$JAVA_HOME/jre/lib/i386/native_threads/
    $ export SCI=/path/to/scilab/
    $ ./myExample
    !sample  for the help  !

      - 42.    42.

## See Also

- api Scilab
- call_scilab
- StartScilab
- SendScilabJob
- SendScilabJobs
- Double Management
- Boolean Management
- Complex Management
- String Management