有关matlab程序转成exe的问题

我在matlab中已实现了一个gui(response.m和response.gif),想转换成独立执行的exe程序。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 C version 2.4.1 in C:\USERS\USER\MATLAB\sys\lcc
[2] Microsoft Visual C/C++ version 6.0 in C:\Program Files\Microsoft Visual Studio

[0] None

Compiler: 1

Please verify your choices:

Compiler: Lcc C 2.4.1
Location: C:\USERS\USER\MATLAB\sys\lcc

Are these correct?([y]/n): y

Try to update options file: C:\Users\user\Application Data\MathWorks\MATLAB\R14SP3\compopts.bat
From template: C:\USERS\USER\MATLAB\BIN\win32\mbuildopts\lcccompp.bat

Done . . .

--> ""C:\Users\user\matlab\bin\win32\mwregsvr" "C:\Users\user\matlab\bin\win32\mwcomutil.dll""

DllRegisterServer in C:\Users\user\matlab\bin\win32\mwcomutil.dll succeeded

--> ""C:\Users\user\matlab\bin\win32\mwregsvr" "C:\Users\user\matlab\bin\win32\mwcommgr.dll""

DllRegisterServer in C:\Users\user\matlab\bin\win32\mwcommgr.dll succeeded

当我再运行 mcc -m response ,会运行一段时间,得到response.ctf,但最终提示错误:
Error: File "response" is a script M-file and cannot be compiled with the current Compiler.
??? Error executing mcc, return status = 1.
问题出在哪里呢?请高手指点赐教,不胜感激涕零。

1.设置编译器:

在确定安装好Matlab Compiler后,还需要对Compiler进行适当的配置,方法是在Matlab命令窗口输入:
Mbuild –setup, 按提示选择matlab自带编译器LCC。

2.将脚本编译为可执行文件:

如项目文件包含:gui.m, gui.gif, fun1.m。
在此路径下命令行输入:mcc –m gui.m,生 成:mccExcludedFiles.log,ReadMe.txt,gui.ctf,gui.prj,gui_main.c,gui_mcc_component_data.c,gui.exe。其中:gui.ctf,gui.exe为脱离matlab环境运行必需的文件。

3.在未安装matlab的机器上运行可执行程序。

将R2 2007b\toolbox\compiler\deploy\win32中的MCRinstaller.exe安装到该计算机上,将生成可执行程序脱离matlab运行所需的函数库。

将2中生成的gui.ctf,gui.exe拷贝到该计算机同一路径。运行gui.exe将生成gui_mcr文件夹,包含程序运行所需的库。至此完成。

4.去除独立可执行程序运行时的“DOS黑窗口”。

以上生成的exe程序运行时首先弹出一个DOS界面窗口,如果不需要其输出数据和错误信息,可将其去除。

matlba命令行输入:

cd(prefdir)
edit compopts.bat

此时compopts.bat打开,在文件最后添加:

set LINKFLAGS=%LINKFLAGS% -subsystem windows

如果程序比较复杂,易出现异常,则不建议去除这个dos窗口以便调试。

另外,这个办法是适用于你用的编译器为LCC,如果是其他的,那么所加语句有所不同

Microsoft Visual C/C++:

set LINKFLAGS=%LINKFLAGS% /SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup

Borland:

set LINKFLAGS=%LINKFLAGS% -aa

5.遇到某些函数不能使用的问题。

我的程序中用到vpa函数,运行gui.exe出现:undefined method or function 'vpa' for input argument type of 'double'错误提示。而gui.m脚本在matlab环境可以运行。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-04-25
貌似得安装动态链接库!