10

我安装了 Visual Studio 2010。但是,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: 

[0] None 

Compiler:

如果我回答n这个问题,我会得到以下信息

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 C++ 9.1 (with Microsoft Visual C++ 2005 SP1 linker) 
[3] Intel Visual Fortran 11.1 (with Microsoft Visual C++ 2008 SP1 linker) 
[4] Intel Visual Fortran 11.1 (with Microsoft Visual C++ 2008 Shell linker) 
[5] Intel Visual Fortran 10.1 (with Microsoft Visual C++ 2005 SP1 linker) 
[6] Microsoft Visual C++ 2005 SP1 
[7] Microsoft Visual C++ 2008 Express 
[8] Microsoft Visual C++ 2008 SP1 

[0] None 

Compiler: 8

The default location for Microsoft Visual C++ 2008 SP1 compilers is C:\Program Files (x86)\Microsoft Visual Studio 9.0, 
but that directory does not exist on this machine.  

Use C:\Program Files (x86)\Microsoft Visual Studio 9.0 anyway [y]/n? n
Please enter the location of your compiler: [C:\Program Files (x86)\Microsoft Visual Studio 9.0] 

编译我的 c++ 代码以使其在 MATLAB 中可用的最简单方法是什么?安装 Visual C++ 2008?oO

4

3 回答 3

7

这取决于您使用的 MATLAB 版本。R2010b 开箱即用支持 VS2010。如果你有 R2010a,有一个可用的补丁:

于 2010-11-02T18:47:13.480 回答
2

解决您的问题的方法不止一种,只有一种涉及金钱:)

  1. 购买/升级到新的 Matlab 版本(R2010b 识别并与 VS2010 一起使用)。
  2. 您不必安装完整的 VS2008 软件包,旧的Windows SDK v7.0就足够了。安装后,matlab 应该会识别出当您执行mbuild -setup.
  3. 正如您自己建议的那样,安装 VS2008。

供将来参考: http: //www.mathworks.com/support/compilers/R2010b/index.html

于 2010-11-02T13:34:07.733 回答
0

您还可以在不使用 mex 的情况下使您的 c++ 代码可用于 Matlab。Matlab 能够加载外部 DLL 并调用它们的函数。因此,您可以将代码包装到 DLL 中,并完全绕过 mex。

一般来说,我发现这是从 matlab 调用 C 或 C++ 代码的一种更简单的方法。缺点是您不会拥有 mex 提供的所有用于操作 matlab 数据结构的工具。仍然可以来回传递数据,有些事情比较麻烦,比如在 C 中分配一个数组并将其所有权交给 matlab。

于 2010-11-02T17:36:13.933 回答