如何将 MATLAB 的 mex 设置定向到Microsoft Windows SDK 进行C++编译?(设置位置时出错)

How to direct MATLAB's mex setup to the Microsoft Windows SDK for C++ compiling? (error in setting location)

本文关键字:设置 编译 C++ 进行 出错 位置 SDK Microsoft MATLAB mex Windows      更新时间:2023-10-16

我在Windows Vista上,想用MATLAB编译C++函数。我在系统上只有lcc compiler,当运行mex -setup时可以看到:

mex -setup
Welcome to mex -setup.  This utility will help you set up  
a default compiler.  For a list of supported compilers, see  
http://www.mathworks.com/support/compilers/R2011a/win32.html 
Please choose your compiler for building 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~1MATLABR2011asyslcc 
[0] None 
Compiler:

由于lcc不适用于c++,所以我从这里(Windows站点)安装了Windows SDK 7.1。我运行Windows SDK 7.1 Command Prompt来查看它被安装到的目录,并查看C:Program FilesMicrosoft SDKsWindowsv7.1。然后我再次运行mex -setup将编译器设置为Microsoft Visual C++ 2010,通过告诉mex不定位已安装的编译器,我选择Microsoft Visual C++ 2010选项,然后MATLAB默认查看的路径是Visual Studio;C:Program FilesMicrosoft Visual Studio 10.0。我试图推翻它,但它不起作用。以下是所采取的具体操作:

>> mex -setup
Welcome to mex -setup.  This utility will help you set up  
a default compiler.  For a list of supported compilers, see  
http://www.mathworks.com/support/compilers/R2011a/win32.html 
Please choose your compiler for building MEX-files: 
Would you like mex to locate installed compilers [y]/n? n
Select a compiler: 
[1] Intel C++ 11.1 (with Microsoft Visual C++ 2008 SP1 linker) 
[2] Intel Visual Fortran 11.1 (with Microsoft Visual C++ 2008 SP1 linker) 
[3] Intel Visual Fortran 11.1 (with Microsoft Visual C++ 2008 Shell linker) 
[4] Lcc-win32 C 2.4.1 
[5] Microsoft Visual C++ 6.0 
[6] Microsoft Visual C++ 2005 SP1 
[7] Microsoft Visual C++ 2008 SP1 
[8] Microsoft Visual C++ 2010 
[9] Microsoft Visual C++ 2010 Express 
[10] Open WATCOM C++ 
[0] None 
Compiler: 8
Warning: The default location for Microsoft Visual C++ 2010 compiler is: 
     "C:Program FilesMicrosoft Visual Studio 10.0" 
     but either that directory does not exist or the configuration 
     is invalid. 
Use C:Program FilesMicrosoft Visual Studio 10.0 anyway [y]/n? n
Please enter the location of your compiler: [C:Program FilesMicrosoft Visual Studio 10.0] 
C:Program FilesMicrosoft SDKsWindowsv7.1
Please verify your choices: 
Compiler: Microsoft Visual C++ 2010  
Location: C:Program FilesMicrosoft Visual Studio 10.0 
Are these correct [y]/n?  
***************************************************************************** 
Error: Microsoft Visual C++ 2010 requires the Microsoft Windows Software  
     Development Kit (SDK), but the SDK cannot be found.  Examine your   
     Microsoft Visual C++ 2010 installation. 
*****************************************************************************  
??? Error using ==> mex at 208
Unable to complete successfully.

我不知道这个目录是否应该和C:Program FilesMicrosoft SDKsWindowsv7.1不同,是否有办法识别这个目录。我也不知道我给目录的方式是否正确。我试着在目录名称周围使用单引号,唯一的变化是它停止问我visual studio的目录是否正确,我回答n,只有这是给定的。

Compiler: Microsoft Visual C++ 2010  
Location: C:Program FilesMicrosoft Visual Studio 10.0 
Are these correct [y]/n? n
mex: No compiler selected. No action taken. 

我如何将编译器添加到MATLAB中才能在c++函数/文件上运行mex ?

如果您是在快速简便的方法之后(并且不使用64位matlab),我建议您下载Visual Studio 2010 c++ express的免费副本并使用它。这样mex -setup就会检测到它。