help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calling Octave from C++


From: Tatsuro MATSUOKA
Subject: Re: Calling Octave from C++
Date: Tue, 27 Mar 2018 14:34:53 +0900 (JST)




----- Original Message -----
> From: Mike Miller <address@hidden>
> To: address@hidden
> Cc: 
> Date: 2018/3/27, Tue 13:51
> Subject: Re: Calling Octave from C++
> 
> On Tue, Mar 27, 2018 at 13:39:26 +0900, Tatsuro MATSUOKA wrote:
>>  For me something seems wrong with octave-4.2.2.
>>  Upcoming 4.4 (now still 4.3.0+), code rewrite as indicated by Mike,
>>  problem seems to be solved.
> 
> As I tried to show in my last message, the example is different for
> Octave 4.2 vs 4.4.
> 
> In Octave 4.2, you need to initialize the interpreter with
> 
>     string_vector argv (2);
>     argv(0) = "embedded";
>     argv(1) = "-q";
>     octave_main (2, argv.c_str_vec (), 1);
> 
> In Octave 4.4, you need to initialize the interpreter with
> 
>     octave::interpreter interpreter;
>     int status = interpreter.execute ();
> 
> -- 
> mike

Thanks Mike. That worked.

#include <iostream>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
#include <octave/interpreter.h>

int
main (void)
{
    string_vector argv (2);
    argv(0) = "test_01_03";
    argv(1) = "-q";
    octave_main (2, argv.c_str_vec (), 1);

    octave_value_list in;

    // THIS CODE IS WORKING
    int qq =10;
    int rr =15;
    in(0) = octave_value(qq);
    in(1) = octave_value(rr);
    octave_value_list out = feval ("gcd", in, 1);
    std::cout << out(0).int_value ()
              << std::endl;
  return 0;
}

the above worked

#include <iostream>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
#include <octave/interpreter.h>

int
main (void)
{
    string_vector argv (2);
    argv(0) = "test_02";
    argv(1) = "-q";
    octave_main (2, argv.c_str_vec (), 1);

    octave_value_list in;

    // THIS CODE IS WORKING
    int qq =10;
    int rr =15;
    in(0) = octave_value(qq);
    in(1) = octave_value(rr);
    octave_value_list out = feval ("pp", in, 1);
    std::cout << out(0).int_value ()
              << std::endl;
  return 0;
}

the above hanged as original author (Andrea) told,

$ LC_ALL=C gdb ./test_02

[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffe3cae700 (LWP 4060)]
[New Thread 0x7fffe14ad700 (LWP 4061)]
[New Thread 0x7fffdecac700 (LWP 4062)]
[New Thread 0x7fffdc4ab700 (LWP 4063)]
[New Thread 0x7fffd9caa700 (LWP 4064)]
[New Thread 0x7fffd94a9700 (LWP 4065)]
[New Thread 0x7fffd4ca8700 (LWP 4066)]

Thread 1 "test_02" received signal SIGSEGV, Segmentation fault.
tree_statement_list::accept (this=0xa4dc30, tw=...)
    at ../libinterp/parse-tree/pt-stmt.cc:326
326      tw.visit_statement_list (*this);
(gdb) bt
#0  tree_statement_list::accept (this=0xa4dc30, tw=...)
    at ../libinterp/parse-tree/pt-stmt.cc:326
#1  0x00007ffff731e106 in octave_user_function::do_multi_index_op (
    this=0x7c1d80, nargout=1, _args=..., lvalue_list=0x0)
    at ../libinterp/octave-value/ov-usr-fcn.cc:610
#2  0x00007ffff7317b84 in octave_user_function::do_multi_index_op (
    this=<optimized out>, nargout=<optimized out>, args=...)
    at ../libinterp/octave-value/ov-usr-fcn.cc:461
#3  0x00007ffff73218e5 in octave_value::do_multi_index_op (
    address@hidden, address@hidden, idx=...)
    at ../libinterp/octave-value/ov.cc:1529
#4  0x00007ffff73aa69b in feval (name="pp", args=..., address@hidden)
    at libinterp/parse-tree/oct-parse.yy:4807
#5  0x0000000000401d72 in main () at test_02.cc:22
(gdb) s
Couldn't get registers: No such process.
Couldn't get registers: No such process.
Couldn't get registers: No such process.
(gdb) [Thread 0x7fffd4ca8700 (LWP 4066) exited]
[Thread 0x7fffd94a9700 (LWP 4065) exited]
[Thread 0x7fffd9caa700 (LWP 4064) exited]
[Thread 0x7fffdc4ab700 (LWP 4063) exited]
[Thread 0x7fffdecac700 (LWP 4062) exited]
[Thread 0x7fffe14ad700 (LWP 4061) exited]
[Thread 0x7fffe3cae700 (LWP 4060) exited]

Tatsuro




reply via email to

[Prev in Thread] Current Thread [Next in Thread]