Compiling pnet (or any other MEX file) with Visual Studio Express and Octave

Octave supports MEX files, just like MATLAB. Here’s how to compile a MEX file (in my case pnet):

  • Run Developer Tools (2012)
  • Change Octave’s math.h to specify correct MS math.h
  • Add Octave ‘bin’ folder to path
  • Change to the folder with the files
  • Run command:
    mkoctfile --mex -lws2_32.lib -DWIN32 -v -o pnet pnet.c
  • The last command fails because a random .lib gets added somehow. Run manually (change paths for your installation):
    link -nologo -DLL -out:pnet.mex pnet.o ws2_32.lib -LIBPATH:C:\bin\Octave-3.6.4\lib\octave\3.6.4 -LIBPATH:C:\bin\Octave-3.6.4\lib octinterp.lib octave.lib cruft.lib -export:mexFunction -incremental:no dirent.lib msvcmath.lib
    I’ve forgotten how I figured that out, so sorry if I’m not giving credit if it’s due somewhere!