The libraries Octave itself uses, can be utilized in standalone applications. These applications then have access, for example, to the vector and matrix classes as well as to all the Octave algorithms.
The following C++ program, Example 2-1, uses
class Matrix
from
liboctave.a or liboctave.so.
Example 2-1. "Hello World!" program using Octave's libraries.
#include <iostream> #include "oct.h" int main(void) { std::cout << "Hello Octave world!\n"; const int size = 2; Matrix a_matrix = Matrix(size, size); for (int row = 0; row < size; ++row) { for (int column = 0; column < size; ++column) { a_matrix(row, column) = (row + 1)*10 + (column + 1); } } std::cout << a_matrix; return 0; }
mkoctfile can once again be used to compile our application:
$ mkoctfile --link-stand-alone hello.cc -o hello $ ./hello Hello Octave world! 11 12 21 22 $