The problem is not in the code but in the way you are compiling and linking the oct-file to be called from Octave. When you built ising3d_fort2oct
, you did not instruct it to link with or how to find the ising3d
Fortran function.
You can link these two source files together in one of two ways. You can compile each individually and then link the resulting object files together, or you can call mkoctfile
once with both source files and let it do everything for you.
To build the oct-file from both sources with one command, do
octave:1> mkoctfile ising3d_fort2oct.cc ising3d.f
in the Octave shell, where mkoctfile
is told about the second source file to compile and link together with the first.
To build the Fortran subroutine separately, as you were attempting to do, and then link it later with the oct-file wrapper, you can instead do
octave:1> system ("gfortran -c ising3d.f -o ising3d.o");
octave:2> mkoctfile ising3d_fort2oct.cc ising3d.o
Note that you still need to link the oct-file with the object file explicitly. Otherwise the oct-file will be compiled assuming that the function is provided by Octave itself or by a system library, and that is why you get an undefined symbol error.