最近在做C++调用matlab的混合编程,觉得有必要搞清楚下mcc的命令。比人版本matlab2011a,在matlab下利用-help mcc密令认真看了下解释,下载将其翻译成中文以便大家理解,不对的请在贴后面留言,我会在看到后第一时间更正。
MCC Invoke MATLAB to C/C++ Compiler (Version 4.15). 这一句不用说了,就是C/C++调用matlab的编译器(版本4.15)
MCC [-options] fun [fun2 ...] 若M文件多于一个,那么每个文件对应转化相应的c和c++文件,若源文件包含c文件,则将它们同新生成的c文件一起编译。
Prepare fun.m for deployment outside of the MATLAB environment. 准备好需要的m文件
Generate wrapper files in C or C++ and optionally build standalone binary files. 生成C/C++文件并有选择性的生成需要的二进制文件
Write any resulting files into the current directory, by default. 默认生成文件保存在当前路径下,即下图所示文本框中目录
The only exception to this rule is when the file is specified with a '-a' flag.
If C or object files are specified, they are passed to MBUILD along with any generated C files. 指定的C或者目标文件将连同其它文件一同传给MBULID生成
If conflicting options are presented to MCC, the rightmost conflicting option is used. MCC接收到多个冲突时采用最右边那个
OPTIONS: 选项
a <filename> Add <filename> to the CTF archive. If the specified file is an M, mex or p file, this function will not be exported in the resulting target. CTF的全称Component Technology File,这是一种归档技术,通过它,MATLAB将可部署文件包装起来。如果指定的文件是一个M、mex或p文件,此功能将无法 输出到目标。
b Generate an MS Excel compatible formula function for the given list of MATLAB functions (requires MATLAB Builder EX). 生成一个兼容MS Excel公式函数的MATLAB函数列表(需要MATLAB Builder的EX)。此选项将在未来的版本MATLAB Builder的EX过时。
B <filename>[:<arg>[,<arg>]] Specify bundle file. <filename> is a text file containing Compiler command line options. <文件名>[:的<arg>的<arg>]指定包文件。 <filename>包含编译器命令行选项的文本文件。这些文件中的换行符是允许的,被视为空白。 MathWorks公司提供文件的下列选项:(具体的就不解释了,在生成的文件中可以看到该选项会有默认的宏,有大牛可以解释下)
ccom
cexcel
cjava
cpplib
csharedlib
dotnet
C For stand-alone applications and shared libraries, generate a separate CTF archive. If this option is not specified, the CTF will be embedded within the stand-alone application or library. 对于独立的应用程序和共享库,生成一个单独的CTF归档。如果没有指定这个选项,CTF将被嵌的独立应用程序或库。
c C only. Generate C wrapper code. This is equivalent to "-T codegen" as the rightmost argument on the command line.C,生成C包装代码。这是相当于“-T代码生成器”
在命令行中最右边的参数,不生成mex文件或者独立应用程序。(示例中lib和dll不在生成)
d <directory> Output directory. All generated files will be put in <directory>. 输出文件在指定目录,需要存在( mcc -d C:\Users\Administrator\Desktop\待处理\mcc处理\aa -W cpplib:libGet_coef Get_coef.m)
e Macro that generates a C Windows application on the Windows platform. 宏生成一个C在Windows平台上的Windows应用程序。
On non-Windows platforms, it is the same as the macro -m. 非Windows平台上,它与m-宏观相同。
This is equivalent to the options "-W WinMain -T link:exe", which can be found in the file <MATLAB>/toolbox/compiler/bundles/macro_option_e. 与“"-W WinMain -T link:exe”等价,也可以在<MATLAB>/toolbox/compiler/bundles/macro_option_e可以找到(实验密令 mcc -e Get_coef.m)
f <filename> Override the default options file with the specified options file when calling MBUILD. This allows you to use different ANSI compilers. <文件名>,调用 MBUILD覆盖默 认的选项文件中指定的选项文件。 这使您可以使用不同的 ANSI编译器。这个选项是直接通过MBUILD 支持脚本。参见“外部接口”文档了解更多信息。
g Debug. Include debugging symbol information. 进入调试状态,包括调试符号资讯。
I (大i) <path> Include path. Add <path> to the list of paths to search for files. 指定文件所在目录,默认(不指定时候)当前工作目录。(使得可以调用其它目录下m文件,实验密令 mcc -e -g -I C:\Users\Administrator\Desktop\待处理 norm.m)
l(小L) Create function library. This option is equivalent to -W lib -T link:lib.The library name can specified with the -n option. 创建lib文件,相当于指令 -W lib -T link:lib。lib文件名可以用-n指定
m Macro that generates a C stand-alone application. This is equivalent to the options "-W main -T link:exe“ 宏生成一个C单机应用。
M "<string>" Pass <string> to the MBUILD script to build an executable.向MBLID或者mex教本传递string中包含的信息,如果M是多次使用,最右边的发生被使用。
N Clear path. 清除除了特殊目录(包含子目录)的所有搜索目录
o <outputfilename> Output name. 输出文件名称,默认第一个文件的文件名,可以用-W指定
p <directory> Add <directory> to the compilation search path. 添加编译路径,必须和-N一同使用。目录不存在采用当前路径
R <option> Specify the run-time options for the MATLAB Common Runtime (MCR) usage:指定MCR运行时的日志文件
EXAMPLES:
mcc -e -R '-logfile,bar.txt' -v foo.m
mcc -m -R -nojvm -v foo.m
mcc -m -R -nodisplay -v foo.m
mcc -m -R -nojvm -R -nodisplay -v foo.m
mcc -m -R '-nojvm,-nodisplay' foo.m
mcc -m -R '-logfile,bar.txt,-nojvm,-nodisplay' -v foo.m
S Create Singleton MCR (不理解有说法是转化为simuink的s函数,求回帖指导)
T <option> Specify target phase and type. The following table shows valid <option> strings and their effects: 指定目标阶段和类型。以下的表格显示有效的<option>字符串及其效果:
codegen - Generate a C/C++ wrapper file. (This is the default -T setting.)
compile:exe - Same as codegen, plus compile C/C++ files to object form suitable for linking into a stand-alone executable.
compile:lib - Same as codegen, plus compile C/C++ files to bject form suitable for linking into a shared library/DLL.
link:exe - Same as compile:exe, plus link object files into a stand-alone executable.
link:lib - Same as compile:lib, plus link object files into a shared library/DLL.
u Register the resulting COM 为当前用户只有在开发机器上注册COM组件,它适用于通用的COM组件和Excel。
v Verbose 显示详细编译步骤
w list. List the warning string 列出警告列表
W <option> Wrapper functions. Specify which type of wrapper file should be generated by the Compiler. <option> can be one of 指定生成文件类型
"main", "WinMain", "lib:<string>", "cpplib:<string>", "com:<component-name>,<class-name>,<version>", or "none"(default).
For the lib wrapper, <string> contains the name of the shared library to build.
Y <license.dat file> Override the default license.dat file with the specified argument. 覆盖默认的license.dat文件中指定的参数。
EXAMPLES:
注意使用mcc前需要运行mbuild,从MATLAB选择支持的C / C ++编译器。
Make a stand-alone C executable for myfun.m:
mcc -m myfun
Make stand-alone C executable for myfun.m.
Look for myfun.m in the directory /files/source, and put the resulting C files and executable in the directory /files/target:
mcc -m -I /files/source -d /files/target myfun
Make a stand-alone C executable from myfun1.m and myfun2.m (using one mcc call):
mcc -m myfun1 myfun2
Make a C shared/dynamically linked library called "liba" from a0.m and a1.m
mcc -W lib:liba -T link:lib a0 a1
Make a CPP shared/dynamically linked library called "liba" from a0.m and a1.m
mcc -W cpplib:liba -T link:lib a0 a1