I am trying to compile a basic c++ .mex and .oct file using the octave environment. The .mex file is just mexcpp.cpp file from matlab which you can get in MATLAB using
edit([matlabroot '/extern/examples/mex/mexcpp.cpp']);
The .oct file is the simple c++ example on found [here].(http://www.gnu.org/software/octave/doc/interpreter/Getting-Started-with-Oct_002dFiles.html)
I struggled for a bit with getting the visual studio compiler to setup all of the environment variables as documented on the octave wiki using vcvarsall.bat. Before the compiler environment variables were set up I could issue the mkoctfile -v --mex mexcpp.cpp command without any errors but no files were created.
Instead I had to specify the environment (I used x86) like so:
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
Now the real problem I have been having is getting my .mex and .oct files to compile. When I try to compile the file I get:
cc-msvc -d -c -D_WIN32 -DWIN32 -D__WIN32__ -IC:\Octave-3.6.2\include\octave-3.6.2\octave\.. -IC:\Octave-3.6.2\include\octave-3.6.2\octave -IC:\Octave-3.6.2\include -Ic:/Software/VC10Libs/include -Ic:/Software/VC10Libs/include/freetype2 -Ic:/Software/VC10Libs/include -Ic:/Software/VC10Libs/include -O2 -MD -EHsc -wd4244 -fp:strict -fp:except- -I. mexcpp.cpp -o mexcpp.o
cl -nologo -c -D_WIN32 -DWIN32 -D__WIN32__ -IC:\Octave-3.6.2\include\octave-3.6.2\octave\.. -IC:\Octave-3.6.2\include\octave-3.6.2\octave -IC:\Octave-3.6.2\include -Ic:/Software/VC10Libs/include -Ic:/Software/VC10Libs/include/freetype2 -Ic:/Software/VC10Libs/include -Ic:/Software/VC10Libs/include -O2 -MD -EHsc -wd4244-fp:strict -fp:except- -I. mexcpp.cpp -Fomexcpp.o mexcpp.cpp
C:\Octave-3.6.2\include\math.h(74) : fatal error C1083: Cannot open include file: 'c:/Program Files/Microsoft Visual Studio 10.0/VC/include/math.h': No such file or directory cc-msvc -d -shared -o mexcpp.mex mexcpp.o -Wl,-export:mexFunction -LC:\Octave-3.6.2\lib\octave\3.6.2 -LC:\Octave-3.6.2\lib -loctinterp -loctave -lcruft link -nologo -DLL -out:mexcpp.mex mexcpp.o -LIBPATH:C:\Octave-3.6.2\lib\octave\3.6.2 -LIBPATH:C:\Octave-3.6.2\lib octinterp.lib octave.lib cruft.lib -export:mex Function dirent.lib msvcmath.lib
LINK : fatal error LNK1181: cannot open input file 'mexcpp.o'
My Visual C++ directory is located in c:/Program Files (x86)/Microsoft Visual Studio 10.0/VC so I am not sure why it is looking in c:/Program Files/Microsoft Visual Studio 10.0/VC?
I found that that the problem was in Octaves ‘math.h’ file. on line 74 the path to the include file is hardcoded to
c:/Program Files/Microsoft Visual Studio 10.0/VC/include/math.h.I solved the issue by just changing to
c:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include/math.h. I tried compiling both the.mexand the.octfiles and they now work!Edit:
On another note I noticed that octave is also including hardcoded paths for some visual studio paths that don’t exist.