AutoCAD 3DMAX C语言 Pro/E UG JAVA编程 PHP编程 Maya动画 Matlab应用 Android
Photoshop Word Excel flash VB编程 VC编程 Coreldraw SolidWorks A Designer Unity3D
 首页 > VC编程

在MATLAB7.0中编译与发布可执行文件的详细步骤与一些问题解答

51自学网 2015-08-30 http://www.wanshiok.com

原帖与讨论:http://bbs.bccn.net/thread-149780-1-1.html

这是我亲自做的,能在没有安装MATLAB的机子上成功实现运行

今天花了好几个小时才整理出此详细步骤,特拿出来与大家分享

具体步骤如下:(此方法适用于MATLAB 7.0

1.安装C编译器(前提是你的电脑已经安装了VC

>> 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 in D:/MATLAB7/sys/lcc

[2] Microsoft Visual C/C++ version 6.0 in D:/Microsoft Visual Studio

[0] None

Compiler: 2

Please verify your choices:

Compiler: Microsoft Visual C/C++ 6.0

Location: D:/Microsoft Visual Studio

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

Try to update options file: C:/Documents and Settings/Leki/Application Data/MathWorks/MATLAB/R14/compopts.bat

From template:              D:/MATLAB7/BIN/WIN32/mbuildopts/msvc60compp.bat

Done . . .

--> "D:/MATLAB7/bin/win32/mwregsvr D:/MATLAB7/bin/win32/mwcomutil.dll"

DllRegisterServer in D:/MATLAB7/bin/win32/mwcomutil.dll succeeded

--> "D:/MATLAB7/bin/win32/mwregsvr D:/MATLAB7/bin/win32/mwcommgr.dll"

DllRegisterServer in D:/MATLAB7/bin/win32/mwcommgr.dll succeeded

2.MATLAB中,将M文件编译成exe(可执行)文件

>> mcc -m guimcc

  To get started, select MATLAB Help or Demos from the Help menu.

Warning: No matching builtin function available for D:/MATLAB7/toolbox/simulink/simulink/set_param.bi

>>

上面警告的解决方法:

/MATLAB7/toolbox/compiler/deploy/matlabrc.m 中的  

81 set_param(0,'PaperType',defaultpaper);  

82 set_param(0,'PaperUnits',defaultunits);  

注释掉之后,又重新编译了一次,没有警告信息出来了

3.将编译生成的文件发布到没有MATLAB的电脑上

先在 $MATLAB/toolbox/compiler/deploy/win32下找MCRInstaller.exe76M左右)文件

然后在没有装MATLAB的机子上安装MCRInstallerD:/MATLAB Component Runtime

(目录中,最好不要有空格,如用 D:/MCR 就可以了)

设置环境变量,右键点击“我的电脑”-》属性-》高级-》环境变量-》新建

变量名:Path  

变量值:D:/MCR/v70/runtime/win32

然后运行exe文件,每次都是出现DOS界面后,几秒钟就自动关闭了

GUI界面一次都运行不出来,也没有错误信息提示

解决办法:

{ 因为MATLAB需要用到处理器的数学运算部分(MATLAB默认用的是INTEL的数学处理单元),故需要设置一下BLAS(Basic Linear Algebra Subroutines,就是"基础线性几何子程序"的意思)环境变量.  首先请确认你的MATLAB的文件夹中有如下文件:atlas_Athlon.dll(AMD系列的请用这个)  atlas_P4.dll(P4的用这个)atlas_PIII.dll(P3的用这个)atlas_PII.dll(P2的用这个),这些是对应处理器的数值运算优化文件 }

先找到 $MATLAB7/bin/win32目录下的atlas_Athlon.dllAMD系列CPU使用)和atlas_P4.dll(奔4用)文件,放到MCR目录中(随便),然后设置环境变量

变量名:BLAS_VERSION

变量值:D:/MCR/v70/atlas_Athlon.dll

这样设置以后,再运行exe文件就OK了。

注意事项:

编译过程中,很可能会有如下报错

>> mcc -m interface

  To get started, select MATLAB Help or Demos from the Help menu.

??? Unable to locate close;contentwindow as a function on the MATLAB path

Warning: An object instance still exists.

Use the objectdirectory command to see a count of existing instances.

??? Depfun error: 'Unable to locate close;contentwindow as a function on the MATLAB path'

>>

这种情况是因为我将“close;contentwindow”语句写在按钮控件属性的“callback”里面了

{但是如果只是单个语句的话,是可行的(比如:只有contentwindow}

此时,只要将“close;contentwindow”语句写在M文件中按钮的“callback”里,再编译就不会出错了

 

 

 
说明
:本教程来源互联网或网友上传或出版商,仅为学习研究或媒体推广,wanshiok.com不保证资料的完整性。
上一篇:有关VC游戏编程的几点建议  下一篇:Visual C++进程间数据通信的实现