help-octave
[Top][All Lists]
Advanced

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

Re: error: feval: function 'pkg.m' not found


From: Mike Miller
Subject: Re: error: feval: function 'pkg.m' not found
Date: Wed, 9 Jan 2019 12:57:01 -0800
User-agent: Mutt/1.10.1 (2018-07-13)

On Wed, Jan 09, 2019 at 14:04:47 -0600, ola wrote:
> 1) it compiles but returns an error related to memory dump: my_code.cc
> #include <iostream>
> #include <octave/oct.h>
> #include <octave/octave.h>
> #include <octave/parse.h>
> #include <octave/interpreter.h>
> 
> int main(const int argc, const char* argv[]) {
>   feval("pkg", ovl("load", "optim"), 0);                                      
>                                  
> //HERE I get memory dump

In this example, you are not initializing the Octave interpreter before
calling the feval function. If you read the Standalone Programs section
it clearly explains that in order to call script files and built in
functions you need to initialize the interpreter.

This example works in Octave 4.0 and earlier versions

    #include <iostream>
    #include <octave/oct.h>
    #include <octave/octave.h>
    #include <octave/parse.h>
    #include <octave/toplev.h>
    
    int
    main (void)
    {
      string_vector argv (2);
      argv(0) = "embedded";
      argv(1) = "-q";
    
      octave_main (2, argv.c_str_vec (), 1);
    
      feval ("pkg", ovl ("load", "optim"), 0);
    
      clean_up_and_exit (0);
    }

and this example works in Octave 4.4 and later versions

    #include <iostream>
    #include <octave/oct.h>
    #include <octave/octave.h>
    #include <octave/parse.h>
    #include <octave/interpreter.h>
    
    int
    main (void)
    {
      octave::interpreter interpreter;
    
      try
        {
          int status = interpreter.execute ();
    
          if (status != 0)
            {
              std::cerr << "creating embedded Octave interpreter failed!"
                        << std::endl;
              return status;
            }
    
          octave::feval ("pkg", ovl ("load", "optim"), 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;
        }
    }

Unfortunately I am not able to get any examples working with Octave 4.2
at the moment, and I seem to remember there were some problems with
embedding the interpreter in that release that simply couldn't be fixed.

If you can upgrade to the current version of 4.4, that would be best. If
not, you can try working with these examples to see what you can get
working in 4.2, but keep in mind that you have to either call
octave_main or create and initialize an interpreter object.

HTH,

-- 
mike

Attachment: signature.asc
Description: PGP signature


reply via email to

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