Microsoft Visual C++ 2008 和 R2007b 的 Mex 类型

Mex type for Microsoft Visual C++ 2008 and R2007b

我想为 vs2008 使用 mex 类型,matlab2007b.i 尝试了下面的代码。

#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 类型应该做什么?

谢谢

我看到两个问题:

  1. 您不需要包含 <matrix.h><matrix.h> 包含在 <mex.h> 中。尝试:include "mex.h" 而不是 <mex.h>,并删除 include <matrix.h>.
  2. 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:

分步说明:

  1. 转到https://www.mathworks.com/matlabcentral/fileexchange/18508-microsoft-visual-studio-2008-mex-and-mbuild-setup-files
  2. 下载 zip 文件 VS2008Matlab.zip(按页面右上角的 "Download zip" 蓝色按钮)。
  3. 解压缩 zip 文件。
  4. 将文件夹内容 VS2008MATLABMexCompilerFilesX64 复制到:C:\Program Files\MATALB\R2007b\bin\win64\mexopts(假设您的版本在默认安装文件夹中是 64 位)。
  5. 复制文件夹内容VS2008MATLABMBuildCompilerFilesX64到:C:\Program Files\MATALB\R2007b\bin\win64\msbuildopts
  6. 执行 mex -setup,并验证 Visual Studio 2008 在列表中。