Matlab【基础】【02】 将APP打包生成可执行EXE文件

本文详细介绍如何使用MATLAB Compiler工具将MATLAB程序打包成独立的exe应用程序,并解决打包过程中常见的问题,包括配置编译器、处理依赖项及解决运行时版本不匹配等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1 执行命令:>> deploytool

选择【Application Compiler】

 【选择加号,添加你的应用源码】

 

 【点击,Package】进行打包

 

然后,生成了如下的目录结构:


2 mbuild

【设定编译器,由于我的系统右VS2019所以,他会自动弹出来,让我进行配置】

>> mbuild -setup
MBUILD 配置为使用 'Microsoft Visual C++ 2019 (C)' 以进行 C 语言编译。

要选择不同的语言,请从以下选项中选择一种命令:
 mex -setup C++ -client MBUILD 
 mex -setup FORTRAN -client MBUILD

3 mcc

mcc Command Arguments Listed Alphabetically

Option    Description    Comment
-a path
Add path to the deployable archive.
If a folder name is specified, all files in the folder are added. If a wildcard is used all files matching the wildcard are added.
-b    
Generate Excel® compatible formula function.
Requires MATLAB® Compiler™ for Excel add-ins
-B filename[:arg[,arg]]    
Replace -B filename on the mcc command line with the contents of filename.
The file should contain only mcc command-line options. These are MathWorks included options files:
-B csharedlib:foo (C shared library)
-B cpplib:foo (C++ library)
-c    
Generate C wrapper code.
Equivalent to -T codegen
-C    
Direct mcc to not embed the deployable archive in generated binaries.
 
-d directory    
Place output in specified folder.
 
-e    
Suppresses appearance of the MS-DOS Command Window when generating a standalone application.
Use -e in place of the -m option. Available for Windows® only. Use with -R option to generate error logging. Equivalent to -W WinMain -T link:exe
The standalone app compiler suppresses the MS-DOS command window by default. To unsuppress it, unselect Do not require Windows Command Shell (console) for execution in the app’s Additional Runtime Settings area.
-f filename    
Use the specified options file, filename, when calling mbuild.
mbuild -setup is recommended.
-g    
Generate debugging information.
None
-G    
Same as -g
None
-I directory    
Add folder to search path for MATLAB files.
 
-K    
Directs mcc to not delete output files if the compilation ends prematurely, due to error.
mcc's default behavior is to dispose of any partial output if the command fails to execute successfully.
-l    
Macro to create a function library.
Equivalent to -W lib -T link:lib
-m    
Macro to generate a standalone application.
Equivalent to -W main -T link:exe
-M string    
Pass string to mbuild.
Use to define compile-time options.
-N    
Clear the path of all but a minimal, required set of folders.
None
-o outputfile    
Specify name of final output file.
Adds appropriate extension
-p directory    
Add directory to compilation path in an order-sensitive context.
Requires -N option
-R option
Specify run-time options for MATLAB Runtime.
option = -nojvm, -nodisplay, -logfile filename, -startmsg, and -completemsg filename
-S    
Create Singleton MATLAB Runtime.
Default for generic COM components. Valid for Microsoft® Excel and Java® packages.
-T    
Specify the output target phase and type.
Default is codegen.
-u    
Registers COM component for current user only on development machine
Valid only for generic COM components and Microsoft Excel add-ins
-v    
Verbose; display compilation steps.
 
-w option
Display warning messages.
option = list, level, or level:string
where
level = disable, enable, error, off:string, or on:string
-W type
Control the generation of function wrappers.
type = main    cpplib:<string> lib:<string> none com:compname,clname,version
-Y licensefile    
Use licensefile when checking out a MATLAB Compiler license.
The -Y flag works only with the command-line mode.
>>!mcc -m foo.m -Y license.lic
-?    
Display help message.
 


遇到的问题: 

问题1

问题2:


问题三:

已经包含了:gentl的adapter,但是,打包的时候

>> imaqhwinfo

ans = 

  包含以下字段的 struct:

    InstalledAdaptors: {'gentl'}
        MATLABVersion: '9.7 (R2019b)'
          ToolboxName: 'Image Acquisition Toolbox'
       ToolboxVersion: '6.1 (R2019b)'

但是,用Mcc -m编译的话依旧出错:


问题4 

mcc -o MainGui -W 'WinMain:MainGui,version=1.0' -T link:exe -d H:\工作\感维科技\外包项目\通过式轮胎检测\SW\CamerGui\MainGui\for_testing -v H:\工作\感维科技\外包项目\通过式轮胎检测\SW\CamerGui\MainGui.m -r 'D:\Program Files\Polyspace\R2019b\toolbox\compiler\Resources\default_icon.ico' -a C:\ProgramData\MATLAB\SupportPackages\R2019b\toolbox\imaq\supportpackages\gentl 
Compiler version: 7.1 (R2019b)

Dependency analysis by REQUIREMENTS.

Parsing file "H:\工作\感维科技\外包项目\通过式轮胎检测\SW\CamerGui\MainGui.m"
    (referenced from command line).
Generating file "H:\工作\感维科技\外包项目\通过式轮胎检测\SW\CamerGui\MainGui\for_testing\readme.txt".
正在打包...
Creating the bundle...
Creating the install agent URL file...
Failed to embed install agent URL file, H:\工作\感维科技\外包项目\通过式轮胎检测\SW\CamerGui\MainGui\for_redistribution\installAgentURL.txt, in the installer.
Update resource failed: 5
Failed to embed unzip in your application.
Update resource failed: 5
Failed to create the web based installer.
No installer package created. 


问题5 

MainGui Executable

1. Prerequisites for Deployment 

Verify that version 9.7 (R2019b) of the MATLAB Runtime is installed.   
If not, you can run the MATLAB Runtime installer.
To find its location, enter
  
    >>mcrinstaller
      
at the MATLAB prompt.
NOTE: You will need administrator rights to run the MATLAB Runtime installer. 

Alternatively, download and install the Windows version of the MATLAB Runtime for R2019b 
from the following link on the MathWorks website:

    https://www.mathworks.com/products/compiler/mcr/index.html
   
For more information about the MATLAB Runtime and the MATLAB Runtime installer, see 
"Distribute Applications" in the MATLAB Compiler documentation  
in the MathWorks Documentation Center.

2. Files to Deploy and Package

Files to Package for Standalone 
================================
-MainGui.exe
-MCRInstaller.exe 
    Note: if end users are unable to download the MATLAB Runtime using the
    instructions in the previous section, include it when building your 
    component by clicking the "Runtime included in package" link in the
    Deployment Tool.
-This readme file 

3. Definitions

For information on deployment terminology, go to
https://www.mathworks.com/help and select MATLAB Compiler >
Getting Started > About Application Deployment >
Deployment Product Terms in the MathWorks Documentation
Center.


Preparing Runtime...
mcc -o Tyre_check -W 'WinMain:Tyre_check,version=1.0' -T link:exe -d H:\工作\感维科技\外包项目\通过式轮胎检测\SW\CamerGui\Tyre_check\for_testing -v H:\工作\感维科技\外包项目\通过式轮胎检测\SW\CamerGui\MainGui.m -r 'D:\Program Files\Polyspace\R2019b\toolbox\compiler\Resources\default_icon.ico' -a C:\ProgramData\MATLAB\SupportPackages\R2019b\toolbox\imaq\supportpackages\gentl 
Compiler version: 7.1 (R2019b)

Dependency analysis by REQUIREMENTS.

Parsing file "H:\MainGui.m"
    (referenced from command line).
Generating file "H:\SW\CamerGui\Tyre_check\for_testing\readme.txt".
正在打包...
Creating the bundle...
Creating installer zip archive due to contents exceeding maximum Windows program size.
Self contained installer created at H:\for_redistribution\MyAppInstaller_mcr.zip.
Packaging complete.
Elapsed packaging time was: 3 minutes and 55 seconds.

【案,注意绿色部分,其实是mcc 应用的一些参数的办法】 

【如果要调用Gentl Adapter,我做了一点改写的工作就,-a 后面就是调用了adapter】

>> mcc -m -a C:\ProgramData\MATLAB\SupportPackages\R2019b\toolbox\imaq\supportpackages\gentl MainGui.m 

【案,问题的原因是,我安装的地方是一个USB 移动硬盘,而移动硬盘上的文件大小有限制,把他转移到电脑的硬盘上就好了】 


 【如果runtim 版本错误,即使安装好了打包的应用程序,运行的时候,任然会报错】

 

 【案,在程序的打包文件夹里说明文件,有个提示】

我们在命令行里面输入“mcrinstaller” 

>> mcrinstaller

ans =

  'C:\Users\frank_sj\AppData\Local\Temp\frank_sj\MCRInstaller9.7\MATLAB_Runtime_R2019b_win64.zip'

 这里提示一个安装包,我们把他替换成也是之前要求的版本就好了。

【案,正确的版本可以依据要求直接在官网下载】


 笔者搞了很久不行,最后还是在线下载解决了这个问题:


参考:

1

Install and Configure MATLAB Runtime - MATLAB & Simulink - MathWorks 中国

MATLAB生成exe脱离matlab运行可执行程序 - 蒲公英的花 - 博客园 (cnblogs.com)https://www.cnblogs.com/hjj-fighting/p/11381395.htmlMATLAB Runtime - MATLAB Compiler - MATLAB (mathworks.cn)https://ww2.mathworks.cn/products/compiler/matlab-runtime.htmlMATLAB App Designer生成独立GUI(可执行exe)并添加依赖项_star2dust的博客-CSDN博客https://blog.csdn.net/u010038790/article/details/109121710matlab生成exe可执行文件_xiaoxiaoliluo917的博客-CSDN博客_matlab生成exehttps://blog.csdn.net/xiaoxiaoliluo917/article/details/82993493MATLAB--mcc命令 - 小懂 - 博客园 (cnblogs.com)https://www.cnblogs.com/juneja/archive/2008/10/31/1323423.html

 【matlab runtime 包】

Standalone Applications - MATLAB & Simulink - MathWorks 中国https://ww2.mathworks.cn/help/compiler/standalone-applications.html?s_tid=srchbrcmStandalone Applications - MATLAB & Simulink - MathWorks 中国https://ww2.mathworks.cn/help/compiler/standalone-applications.html?s_tid=srchbrcm关于matlab AppDesigner打包和解决程序无法识别Runtime的问题_下雨不撑伞丶的博客-CSDN博客_matlab打包app后无法运行https://blog.csdn.net/weixin_47261774/article/details/110534975?spm=1001.2101.3001.6650.6&utm_medium=distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-6.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~BlogCommendFromBaidu~default-6.no_search_link&utm_relevant_index=9

 【MATLAB】App Designer程序发布部署打包(打包exe程序)_老子姓李!的博客-CSDN博客_app designer打包https://blog.csdn.net/qq_44078824/article/details/121913857?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-1.no_search_link&spm=1001.2101.3001.4242.2&utm_relevant_index=4


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Franklin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值