vs2008+matlab2010b--matlab轉換爲dll的操作步驟 ( 一)

1.m文件編寫

functionb = MyFunc(a)

b = a.*a;

M文件保存爲matrixp.m,保存在F:/test文件夾中。然後在Matlab主窗口中將當前文件夾改爲F:/test

2..下面爲matlab的m文件轉換爲dll的操作步驟。

>> 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 D:\PROGRA~1\MATLAB\R2010b\sys\lcc 
[2] Microsoft Visual C++ 2008 SP1 in D:\Program Files\Microsoft Visual Studio 9.0 
 
[0] None 
 
Compiler: 2
 
Please verify your choices: 
 
Compiler: Microsoft Visual C++ 2008 SP1  
Location: D:\Program Files\Microsoft Visual Studio 9.0 
 
Are these correct [y]/n? y
 
*************************************************************************** 
  Warning: MEX-files generated using Microsoft Visual C++ 2008 require 
           that Microsoft Visual Studio 2008 run-time libraries be  
           available on the computer they are run on. 
           If you plan to redistribute your MEX-files to other MATLAB 
           users, be sure that they have the run-time libraries. 
*************************************************************************** 
 
Trying to update options file: C:\Users\liuyong_wh\AppData\Roaming\MathWorks\MATLAB\R2010b\mexopts.bat 
From template:              D:\PROGRA~1\MATLAB\R2010b\bin\win32\mexopts\msvc90opts.bat 
 
Done . . . 
 
************************************************************************** 
  Warning: The MATLAB C and Fortran API has changed to support MATLAB 
           variables with more than 2^32-1 elements.  In the near future 
           you will be required to update your code to utilize the new 
           API. You can find more information about this at: 
           http://www.mathworks.com/support/solutions/en/data/1-5C27B9/?solution=1-5C27B9 
           Building with the -largeArrayDims option enables the new API. 
************************************************************************** 
 
>> mbuild -setup
Please choose your compiler for building standalone MATLAB applications: 
 
Would you like mbuild to locate installed compilers [y]/n? y
 
Select a compiler: 
[1] Lcc-win32 C 2.4.1 in D:\PROGRA~1\MATLAB\R2010b\sys\lcc 
[2] Microsoft Visual C++ 2008 SP1 in D:\Program Files\Microsoft Visual Studio 9.0 
 
[0] None 
 
Compiler: 2
 
Please verify your choices: 
 
Compiler: Microsoft Visual C++ 2008 SP1  
Location: D:\Program Files\Microsoft Visual Studio 9.0 
 
Are these correct [y]/n? y
 
**************************************************************************** 
  Warning: Applications/components generated using Microsoft Visual Studio   
           2008 require that the Microsoft Visual Studio 2008 run-time       
           libraries be available on the computer used for deployment.       
           To redistribute your applications/components, be sure that the    
           deployment machine has these run-time libraries.                  
**************************************************************************** 
 
Trying to update options file: C:\Users\liuyong_wh\AppData\Roaming\MathWorks\MATLAB\R2010b\compopts.bat 
From template:              D:\PROGRA~1\MATLAB\R2010b\bin\win32\mbuildopts\msvc90compp.bat 
 
Done . . . 
 

>> mcc  -W cpplib:libmatrixp -T link:lib matrixp.m  -C

3.執行完第二步後,會生成以下九個文件

Matlab編譯後會在Test文件夾下生成9個文件,分別是:

mccEcxludedFiles.log

libmatrixp.cpp

libmatrixp.ctf

libmatrixp.dll

libmatrixp.exp

libmatrixp.exports

libmatrixp.h

libmatrixp.lib

readme.txt

我們需要的一共有四個文件

libmatrixp.ctf

libmatrixp.dll

libmatrixp.h

libmatrixp.lib

至此,matlab部分完成,在vs部分見(二)


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章