我想为 vs2008 和 matlab2007b 使用 mex 类型。我尝试了下面的代码。
#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");
}
得到这个错误
'matrix.h': No such file or directory
我在下面用 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:
那么使用 mex 类型应该怎么做呢?
谢谢
最佳答案
我看到两个问题:
- 您不需要包含
<matrix.h>
,<matrix.h>
包含在<mex.h>
中.尝试:include "mex.h"
而不是<mex.h>
, 并删除include <matrix.h>
. -
mex -setup
找不到您的 Microsoft Visual C++ 2008 编译器。
选择菜单应该如下所示:
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
由于Visual 2008比Matlab R2007b更新,Matlab无法自动定位Visual 2008。
有一种方法可以手动添加。
引用这里:https://www.mathworks.com/matlabcentral/newsreader/view_thread/297616
请考虑:我无法完全验证以下说明,因为我没有 Matlab R2007b:
分步说明:
- 转到 https://www.mathworks.com/matlabcentral/fileexchange/18508-microsoft-visual-studio-2008-mex-and-mbuild-setup-files
- 下载 zip 文件 VS2008Matlab.zip(按页面右上角的“下载 zip”蓝色按钮)。
- 解压缩 zip 文件。
- 将文件夹内容 VS2008MATLABMexCompilerFilesX64 复制到:
C:\Program Files\MATALB\R2007b\bin\win64\mexopts
(假设您的版本在默认安装文件夹中为 64 位)。 - 将文件夹内容 VS2008MATLABMBuildCompilerFilesX64 复制到:
C:\Program Files\MATALB\R2007b\bin\win64\msbuildopts
- 执行
mex -setup
,并验证 Visual Studio 2008 在列表中。
关于c++ - Microsoft Visual C++ 2008 和 R2007b 的 Mex 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38583411/