Search code examples
c++matlabmex

Mex type for Microsoft Visual C++ 2008 and R2007b


i want to use mex type for vs2008 and matlab2007b.i tried code below.

#include<iostream>
#include <matrix.h>
#include<mex.h>
using namespace std;
void hello(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
  mexPrintf("Hello World!\n");
}

and get this error

'matrix.h': No such file or directory

and i wrote below in matlab commond win

mex -setup
Please choose your compiler for building external interface (MEX) files: 

Would you like mex to locate installed compilers [y]/n? y

Select a compiler: 
[1] Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2007b\sys\lcc 

[0] None 

Compiler: 

so what is should do to use mex type?

thanks


Solution

  • I see two problems:

    1. You don't need to include <matrix.h>, <matrix.h> is included inside <mex.h>. Try: include "mex.h" instead of <mex.h>, and remove include <matrix.h>.
    2. mex -setup could not locate your Microsoft Visual C++ 2008 compiler.

    The selection menu should look as follows:

    Please choose your compiler for building external interface (MEX) files:

    Would you like mex to locate installed compilers [y]/n? y

    Select a compiler:
    [1] Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2007b\sys\lcc
    [2] Microsoft Visual C++ 2008
    [0] None

    Since Visual 2008 is newer than Matlab R2007b, Matlab can't automatically locate Visual 2008.

    There is a way to add it manually.
    Refer here: https://www.mathworks.com/matlabcentral/newsreader/view_thread/297616

    Please consider: I could not fully verify the following instructions because I don't have Matlab R2007b:

    Step by step instructions:

    1. Go to https://www.mathworks.com/matlabcentral/fileexchange/18508-microsoft-visual-studio-2008-mex-and-mbuild-setup-files
    2. Download the zip file VS2008Matlab.zip (press the "Download zip" blue button on the top right side of the page).
    3. Extract the zip file.
    4. Copy folder content VS2008MATLABMexCompilerFilesX64 to: C:\Program Files\MATALB\R2007b\bin\win64\mexopts (assuming your version is 64 bit in default installation folder).
    5. Copy folder content VS2008MATLABMBuildCompilerFilesX64 to: C:\Program Files\MATALB\R2007b\bin\win64\msbuildopts
    6. Execute mex -setup, and verify Visual Studio 2008 is in the list.