[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 13:39:26 +0900 (JST) |
----- Original Message -----
> From: Tatsuro MATSUOKA
> To: tmacchan; Mike Miller "help-octave andrea.delbravo
> Cc:
> Date: 2018/3/27, Tue 13:19
> Subject: Re: Calling Octave from C++
Try on octave 4.2.2
cd /home/mousei7/work/Octave/octave-ML/Calling_Octave_from_Cpp/octave-4.2.2
export LD_LIBRARY_PATH=/opt/octave-4.2.2/lib/octave/4.2.2:$LD_LIBRARY_PATH
export PATH=/opt/octave-4.2.2/bin:$PATH
echo $LD_LIBRARY_PATH
echo $PATH
octave --version
$ echo $LD_LIBRARY_PATH
/opt/octave-4.2.2/lib/octave/4.2.2:/usr/local/lib
$ echo $PATH
/opt/octave-4.2.2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
$ octave --version
GNU Octave, version 4.2.2
$ LC_ALL=C ./test_01_02
Segmentation fault (core dump)
compiled with -g
$ LC_ALL=C gdb ./test_01_02
Thread 1 "test_01_02" received signal SIGSEGV, Segmentation fault.
octave::cmdline_options::cmdline_options (this=0x7fffffffdcb0, opts=...)
at ../libinterp/octave.cc:249
249 : m_force_gui (opts.m_force_gui),
(gdb) bt
#0 octave::cmdline_options::cmdline_options (this=0x7fffffffdcb0, opts=...)
at ../libinterp/octave.cc:249
#1 0x00007ffff770e2f4 in octave::application::options (this=<optimized out>)
at ../libinterp/octave.h:197
#2 octave::interpreter::interpreter (this=0x7fffffffddf0, app_context=0x0,
embedded=<optimized out>) at ../libinterp/corefcn/interpreter.cc:533
#3 0x0000000000401c85 in main () at test_01_02.cc:12
(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 3558) exited]
[Thread 0x7fffd74a9700 (LWP 3557) exited]
[Thread 0x7fffdbcaa700 (LWP 3556) exited]
[Thread 0x7fffe0cac700 (LWP 3554) exited]
[Thread 0x7fffe14ad700 (LWP 3553) exited]
[Thread 0x7fffe3cae700 (LWP 3552) exited]
[Thread 0x7ffff7fa77c0 (LWP 3548) exited]
Couldn't get registers: No such process.
(gdb) [Thread 0x7ffff7fa77c0 (LWP 3548) exited]
Couldn't get registers: No such process.
(gdb) [Thread 0x7fffde4ab700 (LWP 3555) exited]
Program terminated with signal SIGSEGV, Segmentation fault.
The program no longer exists.
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.
Tatsuro
// C++ code used
#include <iostream>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
#include <octave/interpreter.h>
int
main (void)
{
// Create interpreter.
octave::interpreter interpreter;
try
{
int status = interpreter.execute ();
if (status != 0)
{
std::cerr << "creating embedded Octave interpreter failed!"
<< std::endl;
return status;
}
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;
//clean_up_and_exit(0);
}
catch (const octave::exit_exception& ex)
{
std::cerr << "Octave interpreter exited with status = "
<< ex.exit_status () << std::endl;
}
catch (const octave::execution_exception&)
{
std::cerr << "error encountered in Octave evaluator!" << std::endl;
}
return 0;
}
>
> $ ./test_02
> 5
> 6
> error: octave_base_value::double_value (): wrong type argument '<unknown
> type>'
> error: octave_base_value::int_value (): wrong type argument '<unknown
> type>'
> error encountered in Octave evaluator!
>
> Perhaps I have make mistakes but does not hang.
>
> Tatsuro
- Re: Calling Octave from C++, (continued)
- Re: Calling Octave from C++, andrea.delbravo, 2018/03/24
- Re: Calling Octave from C++, Tatsuro MATSUOKA, 2018/03/25
- Re: Calling Octave from C++, Tatsuro MATSUOKA, 2018/03/26
- Re: Calling Octave from C++, Mike Miller, 2018/03/26
- Re: Calling Octave from C++, Tatsuro MATSUOKA, 2018/03/27
- Re: Calling Octave from C++, Tatsuro MATSUOKA, 2018/03/27
- Re: Calling Octave from C++,
Tatsuro MATSUOKA <=
- Re: Calling Octave from C++, Mike Miller, 2018/03/27
- Re: Calling Octave from C++, Tatsuro MATSUOKA, 2018/03/27
- Re: Calling Octave from C++, Tatsuro MATSUOKA, 2018/03/27
- Re: Calling Octave from C++, andrea.delbravo, 2018/03/27
- Re: Calling Octave from C++, Tatsuro MATSUOKA, 2018/03/27
- Re: Calling Octave from C++, andrea.delbravo, 2018/03/27
Re: Calling Octave from C++, Tatsuro MATSUOKA, 2018/03/22