问题
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
回答1:
I see two problems:
- You don't need to include
<matrix.h>
,<matrix.h>
is included inside<mex.h>
. Try:include "mex.h"
instead of<mex.h>
, and removeinclude <matrix.h>
. 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:
- Go to https://www.mathworks.com/matlabcentral/fileexchange/18508-microsoft-visual-studio-2008-mex-and-mbuild-setup-files
- Download the zip file VS2008Matlab.zip (press the "Download zip" blue button on the top right side of the page).
- Extract the zip file.
- Copy folder content VS2008MATLABMexCompilerFilesX64 to:
C:\Program Files\MATALB\R2007b\bin\win64\mexopts
(assuming your version is 64 bit in default installation folder). - Copy folder content VS2008MATLABMBuildCompilerFilesX64 to:
C:\Program Files\MATALB\R2007b\bin\win64\msbuildopts
- Execute
mex -setup
, and verify Visual Studio 2008 is in the list.
来源:https://stackoverflow.com/questions/38583411/mex-type-for-microsoft-visual-c-2008-and-r2007b