1.
首先确定是不是安装vc编译器。
首先确保在matlab路径下没有别的mbuild文件存在。可以用which mbuild查看。其次,用mbuild -setup设置好编译器;最后,用mcc -m filename.m编译filename.m文件
2.
用mcc -m
filename.m编译一个函数m文件出现错误:'mbuild' 不是内部或外部命令,也不是可运行的程序或批处理文件。Error: An error occurred while shelling out to mbuild (error code =
1). Unable to build executable (specify the -v option
for more information). ??? Error using ==> mcc
Error executing mcc, return status = 1.然后觉得奇怪,以前都能编译的,现在居然不行。细看错误提示,估计是环境变量的问题(由于某些原因,环境变量可能被改变或者丢失),于是往系统环境变量path添加:matlabroot\bin;
--注,这里matlabroot指的是matlab根目录再编译,还是不行,重启matlab,再编译,OK!这里还有个问题,运行产生的exe文件,弹出提示:没有找到mclmcrrt78.dll,因此这个应用程序未能启动。重新安装应用程序可能会修复此问题。要解决这个问题,要再加往环境变量path上加一项:matlabroot\bin\win32;
--注,这里matlabroot指的是matlab根目录同样,重启matlab,再编译即可。另外,matlab2008a编译产生exe文件,却不会产生独立的ctf文件(好像是被matlab嵌入到exe中去了,所以如果你没找到它,不要惊慌)
3.
如过出现了错误。Error: File
"eponscript" is a script M-file and cannot be compiled with the
current Compiler. 说明这个是脚本程序,要在前面的第一行加入
function[]=eponscript(); 后面的eponscript是文件名。
4.
一直想用matlab生成可执行文件,可从来没有认真做过。这次看了看说明,但总是报错:
Undefined command/function 'set_param'
Error in ==> matlabrc at 81
最后终于找到了原因:
将 \MATLAB7\toolbox\compiler\deploy\matlabrc.m
中的
81行set_param(0,'PaperType',defaultpaper);
82行set_param(0,'PaperUnits',defaultunits);
注释掉,或者干脆删掉。
重新编译文件后即可运行。
还有一个问题是同样的原因:
Problem Description:
I
am using the MATLAB Compiler and receive the following
error:
Warning: No matching builtin function available for
$MATLAB/toolbox/simulink/simulink/set_param.bi
(where $MATLAB = the MATLAB root directory on my
machine)
Why is this?
Solution:
This bug has been fixed for Release 14 SP1 (R14SP1). For
previous releases, please read below for any possible
workarounds:
This has been verified as a bug in the MATLAB Compiler 4.0
(R14).
In certain cases you may get a warning/error message
regarding SET_PARAM not being found when using MATLAB Compiler 4.0
(R14). SET_PARAM is a SIMULINK function that is not supported by
MATLAB Compiler.
To resolve this issue, you should modify the following
file:
$MATLAB/toolbox/compiler/deploy/matlabrc.m
(where $MATLAB = the MATLAB root directory on your
machine)
Comment out the following lines (numbers 81 and 82) that
have a call to SET_PARAM.
set_param(0,'PaperType',defaultpaper);
set_param(0,'PaperUnits',defaultunits);
When you are finished, save these changes and issue the
following command at the MATLAB command prompt:
rehash toolboxcache
5.最后安装MCRInstaller.exe时要默认安装,这样就不用自己添加环境变量了。