代码之家  ›  专栏  ›  技术社区  ›  Etan bbum

设置mex以使用Visual Studio 2010编译器

  •  10
  • Etan bbum  · 技术社区  · 15 年前

    我已经安装了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?面向对象

    3 回复  |  直到 13 年前
        1
  •  7
  •   Amro    15 年前

    这取决于你使用的是什么MATLAB版本。R2010b支持VS2010开箱即用。如果您有R2010a,则有一个可用的修补程序:

        2
  •  2
  •   rubenvb    15 年前

    解决问题的方法有1种以上,只有一种涉及金钱:)

    1. 购买/升级到新的Matlab版本(R2010b可识别并与VS2010一起使用)。
    2. Windows SDK v7.0 够了。一旦安装,matlab应该会识别 mbuild -setup .

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

        3
  •  0
  •   Dima    15 年前

    您也可以在不使用mex的情况下将您的c++代码提供给Matlab。Matlab能够加载外部dll并调用它们的函数。所以你可以把你的代码包装成一个DLL,完全绕过mex。

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