From 41372dc603662616acc21e8bacff4771a9954655 Mon Sep 17 00:00:00 2001 From: detailer Date: Fri, 2 Jul 2021 21:39:38 +0530 Subject: added support for Windows --- README.md | 73 +++++++++++++++++++++--- sci_gateway/cpp/builder_gateway_cpp.sce | 24 ++++---- sci_gateway/cpp/sci_octave.cpp | 4 +- src/windows_compile.txt | 2 + thirdparty/windows/include/fun.h | 95 ++++++++++++++++++++++++++++++++ thirdparty/windows/lib/libfun.a | Bin 0 -> 102020 bytes thirdparty/windows/lib/libfun.dll | Bin 0 -> 18330032 bytes 7 files changed, 179 insertions(+), 19 deletions(-) create mode 100644 src/windows_compile.txt create mode 100644 thirdparty/windows/include/fun.h create mode 100644 thirdparty/windows/lib/libfun.a create mode 100644 thirdparty/windows/lib/libfun.dll diff --git a/README.md b/README.md index 9b352c0..335cee9 100644 --- a/README.md +++ b/README.md @@ -3,29 +3,54 @@ This is a scilab toolbox to call octave functions. It requires octave to be installed on the system. ## This toolbox has been built and tested using -1. `OS - Linux Debian 10, Ubuntu 18.10 and 19.10 (64-bit)` +1. `OS - Linux Debian 10, Ubuntu 18.10 and 19.10 (64-bit), Windows 10 (64-bit)` 2. `Octave - Version 4.4.1, 5.1.0` 3. `Scilab - Version 6.0.x` -## Software prerequisites: +--- + +## Software prerequisites +## Linux Run the following commands in the linux terminal 1. `sudo apt-get install build-essential (~117 MB download)` 2. `sudo apt-get install liboctave-dev (~103 MB download)` 3. `sudo apt-get install octave` 4. `sudo apt-get install scilab` -## Install the required octave packages using the below command in linux terminal -1. `sudo apt-get install octave-` -For example, to install signal package in octave, do -1. `sudo apt-get install octave-signal` +Install the required octave packages using the below command in linux terminal +1. `sudo apt-get install octave-` For example, to install signal package in octave, do `sudo apt-get install octave-signal` + + +## Windows +1. Download and Install Scilab 6.0.1 x64 from [Scilab.org](https://www.scilab.org/) +2. Download and Install Octave 4.4.1 x64. (If you use a custom installation path different from the default see troubleshooting section below.) +3. Install Mingw Tollbox for Scilab (https://atoms.scilab.org/toolboxes/mingw/0.10.5). +4. Create an user variable called `'OCTAVE_HOME'` with value equal to the installation directory of Octave (default being: `"C:\Octave\Octave-4.4.1\"`). + +--- + +## Running the Toolbox -## Launch Scilab and run the following commands inside the scilab console +## Linux +Launch Scilab and run the following commands inside the scilab console 1. `cd ` 2. `exec builder.sce` 3. `exec loader.sce` 4. `help octave_fun` (then execute the examples appearing on the help page to test the toolbox) +## Windows +Launch Scilab and run the following commands inside the scilab console +1. `cd ` +2. `exec builder.sce` (If you see erros executing this step, see troubleshooting section.) +3. Add "C:\Octave\Octave-4.4.1\bin" or wherever you installaed Octave to Environment PATH. (You need to follow this step only when you are building the toolbox for the first time). +4. `exec loader.sce` +5. `help octave_fun` (then execute the examples appearing on the help page to test the toolbox) + +--- + ## Building the source + +## Linux In case if executing the builder and loader files in scilab throw an error regarding .so files, you probably need to build the toolbox from source. Do the following on the linux terminal 1. Download the fossee-scilab-octave-toolbox source from [`atoms.scilab.org`](https://atoms.scilab.org) 2. Close scilab, if running @@ -34,4 +59,38 @@ In case if executing the builder and loader files in scilab throw an error regar 5. `make` 6. `make install` +## Windows +1. `cd ` +2. Run the commands in `src/window_compile.txt` in a cmd prompt. +3. Copy `fun.h` to `thirdparty/windows/include`. +4. Copy and Overwrite `libfun.a` & `libfun.dll` to `thirdparty/windows/lib` + +--- + +## Troubleshooting +## Windows +**1. Custom Octave install path** + +If you have a custom Octave installtion path then change the path in `tollbox_root/sci_gateway/cpp/builder_gateway_cpp.sce` for `octave_lib_dir` at Line 43. + +**2. library_name.a not found error on running "exec builder.sce".** + +This usually happens when you build the toolbox on Windows for the first time or from scratch. Simply comment the commands +> octave_lib_dir + "liboctave-6"; +> +> octave_lib_dir + "liboctinterp-6"; + +in `tollbox_root/sci_gateway/cpp/builder_gateway_cpp.sce`. Run `exec builder.sce` to get a sucessful build. Uncomment the commands you just commented and run the builder command once again. This time the toolbox will build sucessfully. + +**3. Mingw gcc file not found/ path errors when running "exec builder.sce".** + +This usually happens when you build the toolbox on Windows for the first time or from scratch and have the octave/bin folder in your PATH, causing conflicts with the gcc version required by Mingw Toolbox. + +Remove "C:\Octave\Octave-4.4.1\bin" (or your Octave installation equivalent) from Environment Variable PATH, build the toolbox and add octave/bin back to your PATH as it is required by loader.sce. + +**4. Some Octave Functions Not Found** + +You are missing the OCTAVE_HOME user variable. See Windows software prerequisites section. + + diff --git a/sci_gateway/cpp/builder_gateway_cpp.sce b/sci_gateway/cpp/builder_gateway_cpp.sce index b83ab7a..0b5f9cb 100644 --- a/sci_gateway/cpp/builder_gateway_cpp.sce +++ b/sci_gateway/cpp/builder_gateway_cpp.sce @@ -37,13 +37,17 @@ Version = opt(2); //Build_64Bits = %f; if getos()=="Windows" then - - third_dir = path_builder+filesep()+'..'+filesep()+'..'+filesep()+'thirdparty'; - lib_base_dir = third_dir + filesep() + 'windows' + filesep() + 'lib' + filesep() + Version + filesep(); - inc_base_dir = third_dir + filesep() + 'linux' + filesep() + 'include'; - threads_dir=third_dir + filesep() + 'linux' + filesep() + 'include' + filesep() + 'pthreads-win32'; - C_Flags=['-D__USE_DEPRECATED_STACK_FUNCTIONS__ -I -w '+path_builder+' '+ '-I '+inc_base_dir+' '+'-I '+threads_dir+' '] - Linker_Flag = [lib_base_dir+"liblibraryname.lib"] + third_dir = path_builder+filesep()+'..'+filesep()+'..'+filesep()+'thirdparty'; + lib_base_dir = third_dir + filesep() + 'windows' + filesep() + 'lib' + filesep(); + inc_base_dir = third_dir + filesep() + 'windows' + filesep() + 'include'+ filesep(); + octave_lib_dir = "C:\Octave\Octave-4.4.1\bin\"; + C_Flags=[' -D__USE_DEPRECATED_STACK_FUNCTIONS__ -I -w '+ path_builder + ' '+ ' -I ' + inc_base_dir + ' ']; + libs = [ + lib_base_dir + "libfun"; + octave_lib_dir + "liboctave-6"; + octave_lib_dir + "liboctinterp-6"; + ]; + Linker_Flag = ""; elseif getos()=="Darwin" then third_dir = path_builder+filesep()+'..'+filesep()+'..'+filesep()+'thirdparty'; @@ -51,7 +55,7 @@ elseif getos()=="Darwin" then inc_base_dir = third_dir + filesep() + 'linux' + filesep() + 'include'; C_Flags=["-D__USE_DEPRECATED_STACK_FUNCTIONS__ -w -fpermissive -I"+path_builder+" -I"+inc_base_dir+" -Wl,-rpath "+lib_base_dir+" "] Linker_Flag = ["-L"+lib_base_dir+"liblibraryname"]; - + libs = []; else//LINUX third_dir = path_builder+filesep()+'..'+filesep()+'..'+filesep()+'thirdparty'; @@ -61,12 +65,12 @@ else//LINUX C_Flags = ["-I"+inc_base_dir]; Linker_Flag = ["-L" + lib_base_dir + " -lfun -Wl,-rpath="+lib_base_dir+" -loctave -loctinterp"] - + libs = []; //disp(C_Flags); //disp(Linker_Flag); end -tbx_build_gateway(toolbox_title,Function_Names,Files,get_absolute_file_path("builder_gateway_cpp.sce"), [], Linker_Flag, C_Flags,[]); +tbx_build_gateway(toolbox_title,Function_Names,Files,get_absolute_file_path("builder_gateway_cpp.sce"), libs, Linker_Flag, C_Flags); clear toolbox_title Function_Names Files Linker_Flag C_Flags; diff --git a/sci_gateway/cpp/sci_octave.cpp b/sci_gateway/cpp/sci_octave.cpp index 156178b..391c932 100644 --- a/sci_gateway/cpp/sci_octave.cpp +++ b/sci_gateway/cpp/sci_octave.cpp @@ -193,7 +193,7 @@ extern "C" { // storing the key inStruct[j].key = malloc(sizeof(wchar_t) * (wcslen(keys[j]) + 1)); - wcpcpy((wchar_t*) inStruct[j].key, keys[j]); + wcscpy((wchar_t*) inStruct[j].key, keys[j]); struct_out = scilab_getStructMatrix2dData(env, in[i], keys[j], 0, 0); // Retrieving Curr Value @@ -266,7 +266,7 @@ extern "C" //printf("%S\n", in1); inStruct[j].str = malloc(sizeof(wchar_t) * (wcslen(in1) + 1)); - wcpcpy((wchar_t*) inStruct[j].str, in1); + wcscpy((wchar_t*) inStruct[j].str, in1); // printf("%s\n", str); } else diff --git a/src/windows_compile.txt b/src/windows_compile.txt new file mode 100644 index 0000000..afc3a87 --- /dev/null +++ b/src/windows_compile.txt @@ -0,0 +1,2 @@ +mkoctfile -c -fPIC fun.cpp +g++ -L C:\Octave\Octave-4.4.1\bin -loctave-6 -loctinterp-6 -shared -o libfun.dll fun.o -Wl,--out-implib,libfun.a \ No newline at end of file diff --git a/thirdparty/windows/include/fun.h b/thirdparty/windows/include/fun.h new file mode 100644 index 0000000..cbc8800 --- /dev/null +++ b/thirdparty/windows/include/fun.h @@ -0,0 +1,95 @@ +// Copyright (C) 2019 - IIT Bombay - FOSSEE +// +// This file must be used under the terms of the CeCILL. +// This source file is licensed as described in the file COPYING, which +// you should have received as part of this distribution. The terms +// are also available at +// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt +// Author: Rupak Rokade +// Organization: FOSSEE, IIT Bombay +// Email: toolbox@scilab.in + +#define fun_h__ +//extern "C" int fun (double* answ, double* in1, int in1_row, std::string name, std::string opt); + +extern "C" +{ + + /** + * @brief Enumeration for the data types suported + * + */ + typedef enum { + TYPE_DOUBLE, /**