Scilab/C4/Developing-Scilab-Toolbox-for-calling-external-C-libraries/English
Developing Scilab Toolbox for calling external C libraries
Author: Rupak Rokade
Keywords: scilab, C, external libraries, interfacing, toolbox
|
|
Show Slide:
Opening Slide |
Welcome to the spoken tutorial on “Developing Scilab Toolbox for calling external C libraries” |
Show Slide:
Learning Objectives |
In this tutorial, we will learn to-
|
Show Slide:
Systems Requirements |
To record this tutorial, I am using-
|
Show Slide:
Pre-requisites |
To practice this tutorial, you should know-
If not, watch the prerequisite Scilab and C tutorials on this website. |
Show Slide | This tutorial makes use of files given in the Code files link on this tutorial page.
These include
Download these before continuing. |
Show Slide | * The Scilab6-Test-Toolbox-master file is a Scilab toolbox.
|
Show Slide | * This toolbox provides two functions: add and multiply.
|
Show Slide | * The toolbox in itself is incomplete and is only the source code.
|
Show Slide | * On a Linux OS, the external library has to be compiled into a shared object file
Let us see how this external library is generated |
Switch to the Downloads folder | Switch to the folder where you have downloaded the external-library.zip file. |
Right-click on the zip file >> Extract here option | Right-click on the zip file and choose Extract here to extract its contents. |
Right-click on external-library directory >> So this option isn't available on my OSI prefered new window to show two things at onceOpen in new tabOpen in new window. | Open the external-library directory in a new window.
To do so, right-click on the external-library directory. Choose the option So this option isn't available on my OSOpen in new tabI prefered new window to show two things at onceOpen in new window. |
gedit mul.c | Locate the mul.c file and double click on it to open it in a text editor. |
Point to mul function definition.
|
You can see it contains a function definition.
The name of this function is mul. Close this file. |
Right-click inside external-library directory >> click on Open in Terminal. | We will build a shared object file out of the mul.c file.
Right-click somewhere inside the external-library directory and click on Open in Terminal. |
Press Ctrl+Alt+T keys
Change directory to external-library |
If you don’t get this option, open the terminal by pressing Ctrl+Alt+T keys together.
However, you will have to manually change the current directory to external-library directory. |
Type ./run.sh >> press Enter | Now type dot slash run dot sh and press Enter.
Ignore the warnings about it cannot remove certain files. However, pay attention to any compilation failure related messages. Now, type ls and press enter You can see a file with name libmul dot so This is our compiled external library that we will be using in our Scilab toolbox |
Show slide | * The run dot sh file is a shell script.
This thirdparty directory is now ready to be used in the test_toolbox
|
Show slide | * Yes. similarLikewise, this too.The process of generating the library
depends on the Operating System in use.
|
Show Slide | * You may also have to explore additional compiler and linker flags during the compilation process.
|
Switch to external-library directory >> Right-click on thirdparty directory >> click on Copy | Switch to the external-library directory.
|
Back to For Novice check, you will have to mention where you have the fileI dont know this folder name. It depends on where they save the filereplace the name of the folderxxxxxxxxxxxxx folder >> Right-click on the zip file >> choose Extract here | Come back to the folder where the Scilab6-Test-Toolbox-master.zip code file is saved.
|
Open Scilab6-Test-Toolbox-master >> Right-click inside this folder >> click on Paste. | Open the folder Scilab6-Test-Toolbox-master
|
This will paste the thirdparty directory inside the
Scilab6-Test-Toolbox-master directory. | |
Show Slide | Now let us learn more about the Scilab toolbox.
|
Show slide | * They make use of the Scilab C API for data processing and communication.
|
Scilab6-Test-Toolbox-master directory >> open sci_gateway | Now come back to the Scilab6-Test-Toolbox-master directory
|
Open cpp | Open the folder cpp. |
Open sci_multiply.cpp | Now, open the file sci underscore multiply.cpp by double-clicking on it.
|
Point to mul.h header | It includes the mul dot h header file. |
Point to fname variable | The fname variable declares the name of this function.
|
Point to the code >> call to mul function | The file also has some code which is followed by a call to the mul function. |
This mul function is defined inside the dot so file that we generated earlier. | |
Put text on screen for this part | Note that you need to understand the Scilab C API in order to fully understand this code. |
Close this file. | Close this file. |
Open builder_gateway_cpp.sce | Locate the file builder underscore gateway underscore cpp dot sce
Right click on it and choose Open with text editor |
Point to variable Function_Names. | See the variable Function underscore Names.
|
Point to variable Files. | See the variable Files.
|
Point to variable Linker_Flag. | Next see the variable Linker underscore Flag.
|
Close this file. | Close this file. |
Start Scilab >> Click on File menu >> Browse for new | Now, let’s start Scilab.
|
Browse to Scilab6-Test-Toolbox-master directory >> click on Ok button. | Browse to Scilab6-Test-Toolbox-master directory and click on the Ok button. |
Scilab console >> type exec builder.sce >> press Enter | On the Scilab console, type e x e c space builder.sce and press Enter. |
Do as per narration | A pop up window will open.
|
This should build the toolbox without any difficulty.
| |
Type exec loader.sce >> press Enter | Then type e x e c space loader dot sce and press enter
|
Type help >> press Enter | Then type help and press Enter.
|
Point to left side >> open test_toolbox
|
On the left hand side, locate the test underscore toolbox and click on it to open it.
|
Click on link for multiply function >> scroll to Examples | Click on the link for multiply function.
|
Click on execute button | Click on the execute button on the top right corner of the example section.
|
Scilab console | Switch to the Scilab console. |
Point to multiply function | See that the multiply function has been called.
|
Put text on the screen for this part. | Now let us see how to write the help content for a function.
|
Scilab6-Test-Toolbox-master directory >> Open macros directory
|
Switch to the Scilab6-Test-Toolbox-master directory.
|
Right-click on multiply.sci >> Open With Text Editor | Right-click on the file multiply.sci and choose Open With Text Editor. |
Point to "multiply" function declaration
|
Notice that this file has a function declaration named multiply.
|
Show slide | * Comments made at the beginning of a function represent the help content.
|
Show slide | A few tips.
|
Show slide | * Do not leave any blank lines in between.
|
Scilab6-Test-Toolbox-master directory >> Open it is not falling in the scope of this tutorialPlease explain about loader.sce file and also the remaining folders such as etc, jar, localesbuilder.sce | Switch to the Scilab6-Test-Toolbox-master directory.
|
Scroll to the end
|
Scroll to the end.
|
Show Slide:
Summary |
Let us summarise.
In this tutorial, we learnt to:
|
Show Slide:
Forum to answer questions |
Do you have questions in this Spoken Tutorial?
Choose the minute and second where you have the question. Explain your question briefly. Someone from the FOSSEE team will answer them. Please visit this site. |
Show Slide:
FOSSEE Forum |
For any general or technical questions on Scilab, visit the FOSSEE forum and post your question. |
Show Slide:
Circuit Simulation |
The FOSSEE team coordinates the Textbook Companion project.
We give Certificates and Honorarium to the contributors. For more details, please visit this site: |
Show Slide:
Lab Migration |
The FOSSEE team coordinates the Lab Migration project.
|
Show Slide:
Acknowledgment |
Spoken Tutorial Project is funded by NMEICT, MHRD, Govt. of India.
|
Thank you slide
|
This is Rupak Rokade from IIT Bombay signing off.
Thank you |