Difference between revisions of "Scilab/C4/Developing-Scilab-Toolbox-for-calling-external-C-libraries/English"
Rupakrokade (Talk | contribs) (Created page with "'''Developing Scilab Toolbox for calling external C libraries''' '''Author: Rupak Rokade''' '''Keywords: scilab, C, external libraries, interfacing, toolbox''' {| style="...") |
Nancyvarkey (Talk | contribs) |
||
Line 22: | Line 22: | ||
Learning Objectives | Learning Objectives | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| In this tutorial, we will learn to- | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| In this tutorial, we will learn to- | ||
− | |||
* Add an external '''C library '''to a '''Scilab Toolbox'''. | * Add an external '''C library '''to a '''Scilab Toolbox'''. | ||
* Build and load a '''Scilab Toolbox''' | * Build and load a '''Scilab Toolbox''' | ||
− | |||
− | |||
|- | |- | ||
Line 33: | Line 30: | ||
Systems Requirements | Systems Requirements | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| To record this tutorial, I am using- | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| To record this tutorial, I am using- | ||
− | + | * '''Ubuntu Linux Operating System''' version 19.10 and | |
− | * '''Ubuntu Linux Operating System '''version | + | |
* '''Scilab''' version 6.0.2 | * '''Scilab''' version 6.0.2 | ||
Line 45: | Line 41: | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| To practice this tutorial, you should know- | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| To practice this tutorial, you should know- | ||
− | |||
* Basics of '''Scilab''' | * Basics of '''Scilab''' | ||
* Basics of '''C programming.''' | * Basics of '''C programming.''' | ||
Line 56: | Line 51: | ||
These include | These include | ||
− | |||
# '''Scilab6-Test-Toolbox-master.zip''' | # '''Scilab6-Test-Toolbox-master.zip''' | ||
− | # ''' | + | # '''external-library.zip''' |
Download these before continuing. | Download these before continuing. | ||
Line 64: | Line 58: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show Slide''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show Slide''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| * The '''Scilab6-Test-Toolbox-master''' file is a '''Scilab toolbox'''. | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| |
+ | * The '''Scilab6-Test-Toolbox-master''' file is a '''Scilab toolbox'''. | ||
* The name of this '''toolbox''' is '''test underscore toolbox.''' | * The name of this '''toolbox''' is '''test underscore toolbox.''' | ||
Line 72: | Line 67: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show Slide''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show Slide''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| * This '''toolbox''' provides two '''functions: add''' and '''multiply.''' | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| |
+ | * This '''toolbox''' provides two '''functions: add''' and '''multiply.''' | ||
* The '''multiply function''' is implemented as an external '''library.''' | * The '''multiply function''' is implemented as an external '''library.''' | ||
Line 78: | Line 74: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show Slide''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show Slide''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| * The '''toolbox''' in itself is incomplete and is only the '''source code'''. | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| |
+ | * The '''toolbox''' in itself is incomplete and is only the '''source code'''. | ||
− | * What is missing is the '''compiled''' version of the external library | + | * What is missing is the '''compiled''' version of the external '''library''' |
− | * Recall that in this case the '''multiply ''' | + | * Recall that in this case the '''multiply function''' is the external '''library''' |
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show Slide''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show Slide''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| * On | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| |
+ | * On ''' Linux OS,''' the external '''library''' has to be compiled into a shared '''object file''' | ||
− | * We call that shared object file as | + | * We call that shared '''object file''' as a '''dot so''' file. |
− | * This | + | * This '''dot so''' file has to be provided via a '''directory''' named '''thirdparty'''. |
* The corresponding '''header file '''must also be provided. | * The corresponding '''header file '''must also be provided. | ||
− | Let us see how this external library is generated | + | Let us see how this external '''library''' is generated. |
|- | |- | ||
Line 102: | Line 100: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| Right-click on the''' zip file >> Extract here '''option | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| Right-click on the''' zip file >> Extract here '''option | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Right-click on the '''zip '''file and choose '''Extract here''' to extract its contents. |
|- | |- | ||
Line 110: | Line 108: | ||
To do so, right-click on the '''external-library directory'''. | To do so, right-click on the '''external-library directory'''. | ||
− | Choose the option | + | Choose the option '''Open in new window.''' |
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''gedit mul.c ''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''gedit mul.c ''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Locate the '''mul.c''' file | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Locate the '''mul.c''' file. |
+ | |||
+ | And double click on it to open it in a '''text editor'''. | ||
|- | |- | ||
Line 149: | Line 149: | ||
However, pay attention to any '''compilation failure''' related messages. | However, pay attention to any '''compilation failure''' related messages. | ||
− | Now, type '''ls''' and press | + | Now, type '''ls''' and press '''Enter'''. |
You can see a file with name '''libmul dot so ''' | 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''' | + | This is our '''compiled''' external '''library''' that we will be using in our '''Scilab toolbox'''. |
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show slide''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show slide''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| * The '''run dot sh '''file is a '''shell script'''. | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| |
+ | * The '''run dot sh '''file is a '''shell script'''. | ||
− | * It contains commands required to compile the external | + | * It contains '''commands''' required to '''compile''' the external '''library mul.c '''file in to a '''dot so''' file. |
− | * It also automatically copies the '''dot so '''file and '''header file''' into a '''directory''' named as '''thirdparty''' | + | * It also automatically copies the '''dot so '''file and '''header file''' into a '''directory''' named as '''thirdparty'''. |
− | This '''thirdparty ''' | + | This '''thirdparty directory''' is now ready to be used in the '''test_toolbox''' |
− | Before that, here are some important points about the library compilation process | + | Before that, here are some important points about the '''library compilation''' process. |
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show slide''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show slide''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| * | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| |
− | + | * The process of generating the '''library''' depends on the '''Operating System''' in use. | |
− | depends on the '''Operating System''' in use. | + | |
− | + | ||
* It also depends on the targeted external '''software library'''. | * It also depends on the targeted external '''software library'''. | ||
Line 181: | Line 180: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show Slide''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show Slide''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| * You may also have to explore additional compiler and | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| |
+ | * You may also have to explore additional '''compiler''' and '''linker flags''' during the '''compilation '''process. | ||
* These could be crucial in order to generate '''libraries''' in the correct form. | * These could be crucial in order to generate '''libraries''' in the correct form. | ||
Line 193: | Line 193: | ||
|- | |- | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| folder >> Right-click on the '''zip''' file >> choose '''Extract here''' |
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Come back to the folder where the '''Scilab6-Test-Toolbox-master.zip''' code file is saved. | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Come back to the folder where the '''Scilab6-Test-Toolbox-master.zip''' code file is saved. | ||
Line 201: | Line 201: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| Open '''Scilab6-Test-Toolbox-master >> '''Right-click inside this folder >> click on '''Paste.''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| Open '''Scilab6-Test-Toolbox-master >> '''Right-click inside this folder >> click on '''Paste.''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Open the folder '''Scilab6-Test-Toolbox-master''' | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Open the folder '''Scilab6-Test-Toolbox-master'''. |
Line 209: | Line 209: | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| This will paste the '''thirdparty directory''' inside the | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| This will paste the '''thirdparty directory''' inside the | ||
− | |||
'''Scilab6-Test-Toolbox-master directory.''' | '''Scilab6-Test-Toolbox-master directory.''' | ||
Line 222: | Line 221: | ||
* These '''gateway functions''' are '''CPP files''' inside the '''sci gateway slash cpp directory'''. | * These '''gateway functions''' are '''CPP files''' inside the '''sci gateway slash cpp directory'''. | ||
− | |||
− | |||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show slide''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show slide''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| * They make use of the '''Scilab C API '''for '''data processing''' and '''communication.''' | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| |
+ | * They make use of the '''Scilab C API '''for '''data processing''' and '''communication.''' | ||
* Refer to this website to understand the '''Scilab C API.''' | * Refer to this website to understand the '''Scilab C API.''' | ||
Line 233: | Line 231: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Scilab6-Test-Toolbox-master '''directory >> open '''sci_gateway''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Scilab6-Test-Toolbox-master '''directory >> open '''sci_gateway''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Now come back to the '''Scilab6-Test-Toolbox-master '''directory | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Now come back to the '''Scilab6-Test-Toolbox-master''' directory. |
Line 278: | Line 276: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| Open '''builder_gateway_cpp.sce''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| Open '''builder_gateway_cpp.sce''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Locate the file '''builder underscore gateway underscore cpp dot sce ''' | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Locate the file '''builder underscore gateway underscore cpp dot sce'''. |
− | Right click on it and choose '''Open with text editor''' | + | Right-click on it and choose '''Open with text editor''' |
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| Point to '''variable Function_Names. ''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| Point to '''variable Function_Names. ''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| See the '''variable Function underscore Names. ''' | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| See the '''variable Function underscore Names.''' |
− | It declares the '''function''' name, the '''gateway function''' name and format. | + | It declares the '''function''' name, the '''gateway function''' name and a format. |
|- | |- | ||
Line 295: | Line 293: | ||
It contains the names of the '''gateway''' files that have to be included in the '''toolbox'''. | It contains the names of the '''gateway''' files that have to be included in the '''toolbox'''. | ||
− | |||
In our case it is '''sci underscore multiply.cpp''' | In our case it is '''sci underscore multiply.cpp''' | ||
Line 307: | Line 304: | ||
− | Even though our compiled library name is '''libmul.so''', on | + | Even though our '''compiled library''' name is '''libmul.so''', on '''Linux''' it is referred to as '''lmul''' |
|- | |- | ||
Line 322: | Line 319: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| Browse to '''Scilab6-Test-Toolbox-master directory''' >> click on '''Ok '''button'''.''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| Browse to '''Scilab6-Test-Toolbox-master directory''' >> click on '''Ok '''button'''.''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Browse to '''Scilab6-Test-Toolbox-master directory''' and click on the '''Ok '''button | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Browse to '''Scilab6-Test-Toolbox-master directory''' and click on the '''Ok '''button. |
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Scilab console >>''' type '''exec builder.sce '''>> press '''Enter''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Scilab console >>''' type '''exec builder.sce '''>> press '''Enter''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| On the '''Scilab console,''' type '''e x e c space builder | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| On the '''Scilab console,''' type '''e x e c space builder dot sce '''and press '''Enter'''. |
|- | |- | ||
Line 344: | Line 341: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| Type '''exec loader.sce '''>> press '''Enter''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| Type '''exec loader.sce '''>> press '''Enter''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Then type '''e x e c space loader dot sce '''and press | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Then type '''e x e c space loader dot sce '''and press '''Enter'''. |
− | This should load the toolbox without any difficulty | + | This should load the '''toolbox''' without any difficulty. |
− | Pay attention to errors, if any | + | Pay attention to errors, if any. |
|- | |- | ||
Line 357: | Line 354: | ||
− | The Scilab | + | The '''Scilab Help''' window will open. |
|- | |- | ||
Line 378: | Line 375: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| Click on '''execute''' button | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| Click on '''execute''' button | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Click on the '''execute''' button on the top right corner of the ''' | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| Click on the '''execute''' button on the top right corner of the '''Examples''' section. |
Line 409: | Line 406: | ||
− | Help content is usually written inside a '''dot''' '''sci''' file inside the macros '''directory.''' | + | '''Help''' content is usually written inside a '''dot''' '''sci''' file inside the macros '''directory.''' |
Line 433: | Line 430: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show slide''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show slide''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| * '''Comments''' made at the beginning of a '''function''' represent the '''help''' content. | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| |
+ | * '''Comments''' made at the beginning of a '''function''' represent the '''help''' content. | ||
* The '''comments''' have to strictly follow a particular format. | * The '''comments''' have to strictly follow a particular format. | ||
Line 444: | Line 442: | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show slide''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show slide''' | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| A few tips. | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| A few tips. | ||
− | |||
− | |||
* Do not make any spelling mistakes. | * Do not make any spelling mistakes. | ||
Line 452: | Line 448: | ||
|- | |- | ||
| style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show slide''' | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:none;padding:0.176cm;"| '''Show slide''' | ||
− | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| * Do not leave any blank lines in between. | + | | style="border-top:none;border-bottom:1pt solid #000000;border-left:1pt solid #000000;border-right:1pt solid #000000;padding:0.176cm;"| |
+ | * Do not leave any blank lines in between. | ||
− | * If you want to leave a blank line, '''comment''' it out | + | * If you want to leave a blank line, '''comment''' it out. |
− | * If the | + | * If the edits are not getting reflected back in the '''help''' page, delete these files as shown. |
|- | |- | ||
Line 463: | Line 460: | ||
− | Locate the file | + | Locate the file '''builder dot sce'''. |
Line 479: | Line 476: | ||
− | The '''tbx_builder_gateway command''' | + | The '''tbx_builder_gateway command''' is required to add an external '''library''' to the '''toolbox'''. |
|- | |- | ||
Line 489: | Line 486: | ||
In this tutorial, we learnt to: | In this tutorial, we learnt to: | ||
− | + | * Add an external '''C library''' to a '''Scilab Toolbox'''. | |
− | * Add an external '''C library''' to a '''Scilab | + | * '''Build''' and load a '''Scilab Toolbox'''. |
− | * '''Build''' and load a '''Scilab Toolbox''' | + | |
|- | |- | ||
Line 527: | Line 523: | ||
We give''' Certificates '''and '''Honorarium''' to the contributors. | We give''' Certificates '''and '''Honorarium''' to the contributors. | ||
− | For more details, please visit this site | + | For more details, please visit this site. |
|- | |- |
Latest revision as of 14:34, 25 May 2020
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 |
|
Show Slide |
|
Show Slide |
|
Show Slide |
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 Open 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 |
This thirdparty directory is now ready to be used in the test_toolbox
|
Show slide |
|
Show Slide |
|
Switch to external-library directory >> Right-click on thirdparty directory >> click on Copy | Switch to the external-library directory.
|
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 |
|
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.
In our case it is sci underscore multiply.cpp |
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 dot 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 Examples 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 |
|
Show slide | A few tips.
|
Show slide |
|
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 |