2010-11-02 69 views
10

我安裝了Visual Studio 2010。但是,MATLAB沒有找到編譯器。設置mex以使用Visual Studio 2010編譯器

>> 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

回答

2

有超過1點的方式在你的問題的工作,只有一個涉及到錢:)

  1. 購買/升級到一個新的matlab版(R2010b中識別並與VS2010的作品)。
  2. 您不必安裝完整的VS2008軟件包,舊的Windows SDK v7.0就足夠了。一旦安裝,matlab應該認識到當你做一個mbuild -setup
  3. 正如你自己的建議,安裝VS2008。

以供將來參考:http://www.mathworks.com/support/compilers/R2010b/index.html

+0

會從我的大學下載R2010b中的版本... – Etan 2010-11-02 13:42:36

0

您也可以提供給Matlab的C++代碼,而無需使用MEX。 Matlab能夠加載外部DLL並調用它們的函數。所以你可以把你的代碼包裝到一個DLL中,並完全繞過mex。

一般來說,我發現這是從MATLAB調用C或C++代碼的更簡單的方法。缺點是你不會擁有所有用於操縱mex提供的matlab數據結構的工具。你仍然可以來回傳遞數據,有些東西比較麻煩,比如在C中分配一個數組並賦予其對matlab的所有權。

+0

我建議在[編譯MEX文件與程序Visual Studio](http://www.orangeowlsolutions.com/news)將mex文件直接編譯到Visual Studio中。該程序已針對Visual Studio 2010,Matlab 2010a和64位Intel目標機器進行了測試。在該網頁中,您可以找到一個「模板」Visual Studio項目,您可以下載並用作自己的參考。你爲什麼說有限制?我沒有立即找到爲什麼你不能在Visual Studio下編譯mex文件和所有的mex功能的原因。 – JackOLantern 2013-07-29 13:15:35