matlab R2013a中将GUI编译成exe

网上找了很多关于将GUI编译成exe的文章,但总是碰到很多问题,经过反复摸索终于搞定在R2013a版本下的编译方法了!先将工作目录切换到fig和m文件所在位置,在命令行中执行相应的命令,具体过程记录如下:

>> mbuild -setup
 
Welcome to mbuild -setup.  This utility will help you set up  
a default compiler.  For a list of supported compilers, see  
http://www.mathworks.com/support/compilers/R2013a/win32.html 
 
Please choose your compiler for building shared libraries or COM components: 
 
Would you like mbuild to locate installed compilers [y]/n? y
 
Select a compiler: 
[1] Microsoft Visual C++ 2010 in F:\Program Files\Microsoft Visual Studio 10.0 
[2] Microsoft Visual C++ 6.0 in C:\Program Files\Microsoft Visual Studio 
 
[0] None 
 
Compiler: 1
 
Please verify your choices: 
 
Compiler: Microsoft Visual C++ 2010  
Location: F:\Program Files\Microsoft Visual Studio 10.0 
 
Are these correct [y]/n? y
 
**************************************************************************** 
  Warning: Applications/components generated using Microsoft Visual C++      
           2010 require that the Microsoft Visual Studio 2010 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: G:\Users\quiklcm\AppData\Roaming\MathWorks\MATLAB\R2013a\compopts.bat 
From template:              F:\MATLAB~1\R2013a\bin\win32\mbuildopts\msvc100compp.bat 
 
Done . . . 
 
>>  mcc -W main -T link:exe isoline
>>

对上述命令的注解:

1)mbuild命令用于安装编译器,由于我的电脑曾经安装过vc6和vs2010,所以mbuild命令找到了上述两个编译器,我选择了第一个;

2)mcc命令就是将我编写的isoline.m和isoline.fig文件编译成isoline.exe文件,命令执行完成后,在工作目录中生成了下面三个文件:

      isoline.exe
      mccExcludedFiles.log
      readme.txt

      就是这个命令,让我琢磨了很久,很多文章说的是执行mcc -m isoline.m命令,我记得以前装Matlab 7.0时,确实是使用该命令来编译的;可是在R2013a下,总是报下面的错误:

      ??? Unable to determine application type, since no wrapper function was specified.Please use the -W switch or specify application type via -m or -l.Type 'mcc -?' for further assistance.

      不过在mcc -W main -T link:exe isoline命令执行成功后,再次执行mcc -m isoline.m,则可以正常运行了!

3)这样编译工作完成了!退出Matlab,双击isoline.exe即可运行。

需要注意的问题:

1)虽然生成的可执行程序可以脱离Matlab环境运行,但是它需要Matlab C/C++数学库文件或者图形库文件的支持才能运行,如果需要在未安装Matlab的机器上运行,则需要按照上面生成的readme.txt中的叙述,安装MATLAB Compiler Runtime (MCR);

2)上面命令行中的警告信息说明,运行exe程序时可能需要vs2010的库文件,具体需要哪些文件,这个待验证了,等我拿到其他机器上测试后,再做研究!

3)运行exe程序时,会出现命令行窗口,该窗口可以显示fprintf命令打印出来的后台消息,主要用于程序调试,如果不需要该命令行窗口,可重新编译,编译命令为:

      mcc -e isoline.m

      重新编译后,运行生成的exe程序,则不会再出现命令行窗口!
 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值