/* Taken from https://octave.org/doc/v4.4.0/Standalone-Programs.html */ #include #include #include #include #include int main (void) { // Create interpreter. octave::interpreter interpreter; try { // Inhibit reading history file by calling // // interpreter.initialize_history (false); // Set custom load path here if you wish by calling // // interpreter.initialize_load_path (false); // Perform final initialization of interpreter, including // executing commands from startup files by calling // // int status interpreter.initialize (); // // if (! interpreter.initialized ()) // { // std::cerr << "Octave interpreter initialization failed!" // << std::endl; // exit (status); // } // // You may skip this step if you don't need to do do anything // between reading the startup files and telling the interpreter // that you are ready to execute commands. // Tell the interpreter that we're ready to execute commands: int status = interpreter.execute (); if (status != 0) { std::cerr << "creating embedded Octave interpreter failed!" << std::endl; return status; } octave::feval ("pkg.m", ovl ("load", "control"), 0); octave_idx_type n = 2; octave_value_list in; for (octave_idx_type i = 0; i < n; i++) in(i) = octave_value (5 * (i + 2)); octave_value_list out = octave::feval ("gcd", in, 1); if (out.length () > 0) std::cout << "GCD of [" << in(0).int_value () << ", " << in(1).int_value () << "] is " << out(0).int_value () << std::endl; else std::cout << "invalid\n"; } 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; } /* To get rid of the error related to libiconv.dll.a not found solution found at https://savannah.gnu.org/bugs/?53920 setenv('OCTAVE_LINK_DEPS', "-lfreetype -lhdf5 -lGraphicsMagick++ -lGraphicsMagick -lz -lfftw3 -lfftw3f \ -lopengl32 -lglu32 -lfontconfig -lfreetype -lgl2ps -ladvapi32 -llapack -lcurl -lcholmod -lumfpack \ -lamd -lcamd -lcolamd -lccolamd -lcxsparse -lsuitesparseconfig -larpack -lqrupdate -lopenblas \ -lreadline -ltermcap -lpcre -lm -lgfortran -lmingw32 -lmoldname \ -lmingwex -lmsvcrt -lquadmath -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lpsapi -lgdi32 \ -lm -lws2_32 -lws2_32 -ladvapi32 -lws2_32 -lws2_32 -liconv") setenv('OCTAVE_LINK_DEPS', " -liconv") */