Getting Started

Octave is a very nice free Matlab clone and provides many helpful mathematical functions. Especially linear algebra calculations are rather easy, but Octave comes also with lot more. For more information and to download octave see the homepage of the project at To use the very powerful Octave functions in your C/C++ programs include the main octave header file

#include <octave/oct.h>

which is mostly located in \usr\local\include\octave-version-number Mostly, it will not be necessary to include further header files, since this file already includes most of the octave functions. Nevertheless we will refer to the respective special headers in the following to give you the chance to gain some further information.

To compile your C/C++ code, e.g. with g++, set the -I option of your compiler to the location of the octave include files. For the linking process octave provides you with a very useful make file mkoctfile. Standardly this make file is also used for translating octave code into .oct files. It comes with the option --link-stand-alone which produces an executable file of your C/C++ program containing octave subroutines. The following Makefile represents a simple example to compile and link your program called test at the end:


all: test

     -rm test.o test

test: test.o
     mkoctfile --link-stand-alone -o test test.o

test.o: main.cpp
     g++ -c -I$(OCTAVE_INCLUDE) -I$(OCTAVE_INCLUDE)octave -o test.o main.cpp

Please note that the spaces before the commands must be a tabulator character according to standard rules of Makefiles. The environment variable $OCTAVE_INCLUDE should be set to your octave include path, which could be, e.g., /usr/include/octave-2.1.73. By using the command make all your program will be compiled and linked.