适用于Microsoft Visual C++2008和R2007b的Mex类型

Mex type for Microsoft Visual C++ 2008 and R2007b

本文关键字:Mex 类型 R2007b Microsoft Visual C++2008 适用于      更新时间:2023-10-16

我想对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中写下了以下内容

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~1MATLABR2007bsyslcc 
[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~1MATLABR2007bsyslcc
[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(按页面右上角的"下载zip"蓝色按钮)
  3. 提取zip文件
  4. 将文件夹内容VS2008MATLABMexCompilerFilesX64复制到:C:Program FilesMATALBR2007bbinwin64mexopts(假设默认安装文件夹中的版本为64位)
  5. 将文件夹内容VS2008MATLABMBuildCompilerFilesX64复制到:C:Program FilesMATALBR2007bbinwin64msbuildopts
  6. 执行mex -setup,并验证Visual Studio 2008是否在列表中