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部分见(二)