Problem with embedding Octave in C++

Hi,
I’m trying to embed the Octave interpreter in some C++, and so I’m trying to follow the examples from here


The difference is that I’m trying to make a standalone program in C++ in Eclipse, rather than use ‘mkoctfile’ as in the examples.

I’ve tried to set up the first example, so my file is

#include
#include <oct.h>
#include <octave.h>
//#include <parse.h>
//#include <interpreter.h>

using namespace std;

int main(void) {

std::cout << "Hello World" << std::endl;

int n = 2;
Matrix a_matrix = Matrix(n,n); 

for (octave_idx_type i=0; i < n; i++)
	for (octave_idx_type j = 0; j<n; j++)
		a_matrix(i,j) = (i + 1) * 10 + (j + 1);

std:cout << a_matrix;


return 0;

}

I’m trying to get this to build in Eclipse, but it fails. as follows…]

12:56:15 **** Incremental Build of configuration Debug for project octaveCaller ****
make all
Building target: octaveCaller
Invoking: GCC C++ Linker
g++ -L/usr/include/octave-5.2.0/octave/ -L/usr/share/octave/5.2.0/etc/tests -o “octaveCaller” ./src/octaveCaller.o
./src/octaveCaller.o: In function main': /home/arwel/eclipseWorkspace_new/octaveCaller/Debug/../src/octaveCaller.cpp:26: undefined reference to operator<<(std::ostream&, Matrix const&)’
./src/octaveCaller.o: In function Array<double>::Array(dim_vector const&)': /usr/include/octave-5.2.0/octave/Array.h:265: undefined reference to dim_vector::safe_numel() const’
./src/octaveCaller.o:(.rodata._ZTV6Matrix[_ZTV6Matrix]+0x20): undefined reference to Array<double>::resize_fill_value() const' ./src/octaveCaller.o:(.rodata._ZTV7NDArray[_ZTV7NDArray]+0x20): undefined reference to Array::resize_fill_value() const’
./src/octaveCaller.o:(.rodata._ZTV6MArrayIdE[_ZTV6MArrayIdE]+0x20): undefined reference to Array<double>::resize_fill_value() const' ./src/octaveCaller.o:(.rodata._ZTV5ArrayIdE[_ZTV5ArrayIdE]+0x20): undefined reference to Array::resize_fill_value() const’
collect2: error: ld returned 1 exit status
make: *** [octaveCaller] Error 1
“make all” terminated with exit code 2. Build might be incomplete.

12:56:15 Build Failed. 3 errors, 0 warnings. (took 126ms)

I’m well aware that the problem here may be that I haven’t much experience with C++ or Eclipse.
In the eclipse projec properties, I have ‘usr/include/octave-5.2.0/octave’. What am I missing here?
Cheers,
Arwel

(I’m on RedHat 7, trying this with octave 5.2.0. The eclipse version seems to be 2019-12

You have to link to liboctave and liboctinterp.
I don’t know Eclipse. But you’ll probably have to add “-loctave -loctinterp” somewhere…