Use package in standalone programs

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Use package in standalone programs

Zoltán Szabó
I am trying to create a small c++ application to execute an octave m file.

So this will be a standalone program as mentioned here:
https://www.gnu.org/software/octave/doc/v4.0.3/Standalone-Programs.html#Standalone-Programs

My m file is using some functions from the signal package. Is it possible to load a package from a standalone program when using octave as a library?

Thanks

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Use package in standalone programs

siko1056
Zoltán Szabó wrote

> I am trying to create a small c++ application to execute an octave m file.
>
> So this will be a standalone program as mentioned here:
> https://www.gnu.org/software/octave/doc/v4.0.3/Standalone-Programs.html#Standalone-Programs
>
> My m file is using some functions from the signal package. Is it possible
> to load a package from a standalone program when using octave as a
> library?
>
> Thanks

For the current Octave development version 4.3.0+ it is possible. Do you
need version 4.0.3 or the current stable version 4.2.1? There it seems to
make some trouble.

Using the current Octave development version 4.3.0+ and the interval package
as example:

```
pkg load interval
infsup (1, 2)
   ans = [1, 2]
```

Extending [1] as a start, the above would translate to:

```
octave::feval ("pkg", ovl ("load", "interval"), 0);
octave_value_list out = octave::feval ("infsup", ovl (1, 2), 1);

if (out.length () > 0)
  octave::feval ("disp", out(0), 0);
```

Compiled with:

mkoctfile --link-stand-alone embedded.cc -o embedded

HTH,
Kai

[1]
https://hg.savannah.gnu.org/hgweb/octave/file/cd42d0f341db/examples/code/embedded.cc



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Use package in standalone programs

Zoltán Szabó
Thank you, I will check this out soon.

Is it possible to use an other compiler like gcc and configure it just like what mkoctfile does? Because I might use gcc as my project requests it.

On Mon, Jan 8, 2018 at 1:28 PM, siko1056 <[hidden email]> wrote:
Zoltán Szabó wrote
> I am trying to create a small c++ application to execute an octave m file.
>
> So this will be a standalone program as mentioned here:
> https://www.gnu.org/software/octave/doc/v4.0.3/Standalone-Programs.html#Standalone-Programs
>
> My m file is using some functions from the signal package. Is it possible
> to load a package from a standalone program when using octave as a
> library?
>
> Thanks

For the current Octave development version 4.3.0+ it is possible. Do you
need version 4.0.3 or the current stable version 4.2.1? There it seems to
make some trouble.

Using the current Octave development version 4.3.0+ and the interval package
as example:

```
pkg load interval
infsup (1, 2)
   ans = [1, 2]
```

Extending [1] as a start, the above would translate to:

```
octave::feval ("pkg", ovl ("load", "interval"), 0);
octave_value_list out = octave::feval ("infsup", ovl (1, 2), 1);

if (out.length () > 0)
  octave::feval ("disp", out(0), 0);
```

Compiled with:

mkoctfile --link-stand-alone embedded.cc -o embedded

HTH,
Kai

[1]
https://hg.savannah.gnu.org/hgweb/octave/file/cd42d0f341db/examples/code/embedded.cc



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Use package in standalone programs

siko1056
Zoltán Szabó wrote
> Is it possible to use an other compiler like gcc and configure it just
> like what mkoctfile does? Because I might use gcc as my project requests
> it.

Sure, just type `mkoctfile -v` and you can see the commands with which g++
is invoked on your system.

HTH,
Kai





--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Use package in standalone programs

Zoltán Szabó
Thanks this is really helpful, I will try to integrate those parameters into my build system.

One other question if you allow me: is it possible to call an already existing m file? My m file has like 20 lines and it is using the mentioned signal package, it just returns a single string for me what I need to process within c++. So if it is possible to just run the m file instead of programming all the 20 line in c++ that would be really good.
(Note: I am not allowed to execute octave cli binary for this, I need to embed octave in my application as a library.)

Thanks,
Zoltan

On Mon, Jan 8, 2018 at 3:12 PM, siko1056 <[hidden email]> wrote:
Zoltán Szabó wrote
> Is it possible to use an other compiler like gcc and configure it just
> like what mkoctfile does? Because I might use gcc as my project requests
> it.

Sure, just type `mkoctfile -v` and you can see the commands with which g++
is invoked on your system.

HTH,
Kai





--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: Use package in standalone programs

siko1056
Zoltán Szabó wrote

> [...] is it possible to call an already existing m file? My m file has
> like 20 lines and it is using the mentioned signal package, it just
> returns a single string for me what I need to process within c++. So if it
> is possible to just run the m file instead of programming all the 20 line
> in c++ that would be really good. (Note: I am not allowed to execute
> octave cli binary for this, I need to embed octave in my application as a
> library.)
>
> Thanks,
> Zoltan

Just a small note: for this mailing list we have the convention to bottom
post [1].

This should work as well.  By using the code of embedded.cc you really
invoke the Octave interpreter (like octave-cli does itself).  Therefore you
are allowed to parse and execute any octave code (scripts, functions,
classes, ... ).  Assume your script is `myscript.m` and available on Octaves
load path.  Then calling from C++:

```
octave::feval ("myscript", ovl (), 0);
```

should suffice.

HTH,
Kai

[1] https://en.wikipedia.org/wiki/Posting_style#Bottom-posting



--
Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave