matlab生成C++文件mcc命令

轉載https://blog.csdn.net/liuci3234/article/details/8916205

最近在做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.    默認生成文件保存在當前路徑下,即下圖所示文本框中目錄

  For all targets except standalone, if more than one file is  specified, a C or C++ interface is generated for each file.  C/C++接口將生成除了特別指定以外(即下面用-a密令指定處理方式的文件)的所有文件
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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章