Main Content

Relocate or Share Generated Code

To relocate or share static and generated code files, you can use thepackNGo功能。For example, use the function when you want to relocate generated code to a development environment that does not provide MATLAB®and Simulink®s manbetx 845产品。

Package and Relocate Generated Code

到包装生成的代码:

  1. In the Configuration Parameters dialog box, selectPackage code and artifacts。This option configures the build process to run thepackNGo代码生成后的功能。

  2. In theZip file namefield, enter the name of the ZIP file in which you want to package the generated code and artifacts. You can specify the file name with or without the。压缩扩大。如果您不指定扩展名或扩展。压缩,,,,the ZIP utility adds the。压缩扩大。If you do not specify a value, the build process uses the namemodel。压缩,,,,wheremodelis the name of the top model.

  3. Apply the changes and then generate code for your model.

  4. Verify that the packaged code is ready for relocation by using a ZIP tool to inspect the resulting ZIP file.

Relocate the ZIP file to the destination development environment and use a ZIP tool to unpack the file. To compile the unpacked code, use a build tool.

If the destination environment providesSimulink Coder™或嵌入式编码器®, 您可以使用CodeBuild编译未包装的代码。

包装并从命令行重新分配生成的代码

要通过使用行命令打包和重新分配生成的代码,请使用此工作流:

选择zip文件的结构

Before you generate and package the files for a model build, decide whether you want the files to be packaged in a flat or hierarchical folder structure. By default, thepackNGo功能将文件包装在单个扁平文件夹结构中。

如果... 然后使用. .。
您将文件重新定位到不使用生成的makefile的IDE,或者代码不取决于所需的静态文件的相对位置 单个扁平文件夹结构
这destination development environment must maintain the folder structure of the source environment because it uses the generated makefile, or the code depends on the relative location of files 层次结构

If you use a hierarchical structure, thepackNGo功能创建两个级别zipfiles, a primaryzip文件又包含以下次要zip文件:

  • mlrfiles.zip- 您的文件matlabrootfolder tree

  • sDirFiles.zip- 您的构建文件夹中的文件和下方的文件在其中启动了模型的代码生成

  • 其他files.zip- 所需的文件不在matlabrootor开始folder trees

次要的路径zip文件相对于主文件夹zip文件,维护源开发文件夹结构。

Select a Name for the Zip File

默认情况下,packNGofunction names the primaryzipfilemodel。You have the option of specifying a different name. If you specify a file name and omit the file type extension, the function appends您指定的名称。

Package Model Code in a Zip File

Package model code files by using the邮政编码configuration parameter,packNGo功能,并为模型构建信息对象。您可以设置包装操作以使用:

  • 系统生成的构建信息对象。

    In this case, before generating the model code, useset_paramto set the configuration parameter邮政编码明确呼叫packNGo功能。例如:

    set_param(bdroot,'postcodegencommand','packngo(buildInfo);');

    在生成和编写模型代码到磁盘和生成makefile之前,此命令指示构建过程以评估调用的呼叫packNGo。此命令使用当前选择的模型的系统生成的构建信息对象。

  • A build information object that you construct programmatically.

    In this case, you could use other build information functions to include paths and files selectively in the build information object that you then specify with thepackNGo功能。例如:

    。。。mymodelbuildinfo = rtw.buildinfo;AddSourceFiles(mymodelbuildinfo,{'test1.c'test2.c''driver.c'});。。。Packngo(mymodelbuildinfo);

以下示例显示了如何更改的默认行为packNGo

To... 指定...
Change the structure of the file packaging to hierarchical Packngo(buildInfo,'packType''risrarchical');
重命名初选zipfile Packngo(buildInfo,'filename''zippedsrcs');
Change the structure of the file packaging to hierarchical and rename the primaryzipfile packNGo(buildInfo, 'packType' 'hierarchical'...
'filename''zippedsrcs');
在包含路径上找到的标题文件zipfile Packngo(buildInfo,“ minimalheaders'false);
Generate warnings for parse errors and missing files packngo(buildinfo,'ignoreParseError'true ...
'ignoreFileMissing' true);

笔记

packNGofunction can modify the build information in thertw.buildinfo作为函数的第一个参数传递的对象。该函数可能会从源中找到其他文件,并包括在模型的构建信息中记录的路径,并将该信息添加到rtw.buildinfoobject.

检查Generated ZIP File

要验证生成的ZIP文件已准备好进行重新定位,请使用zip工具检查文件。一些ZIP工具允许您在不打开文件的情况下查看文件内容。如果需要解开包装,并且将模型代码文件打包为层次结构,则必须解开主要和辅助ZIP文件。当您解开辅助ZIP文件时,保留了文件的相对路径。

重新安置和解开zip文件

Relocate the ZIP file to the destination development environment and use a ZIP tool to unpack the file. To compile the unpacked code, use a build tool.

If the destination environment providesSimulink Coder或嵌入式编码器,您可以使用CodeBuild编译未包装的代码。

代码包装Example

此示例显示了如何打包为示例模型生成的代码文件rtwdemo_rtwintro

  1. Set your working folder to a writable folder.

  2. Open the modelrtwdemo_rtwintro并将副本保存到工作文件夹中。

  3. In the Command Window, enter:

    set_param('rtwdemo_rtwintro',,,,'PostCodeGenCommand',,,,...'packngo(buildInfo,''packType'''''''''')'');
  4. 为模型生成代码。

  5. 检查生成的zip文件,rtwdemo_rtwintro.zip。zip文件包含两个辅助zip文件,mlrfiles.zipandsDirFiles.zip

  6. 检查mlrfiles.zipandsDirFiles.zip

  7. 将ZIP文件重新放置到您的目标文件夹,然后打开包装。

  8. To compile the unpacked code, use theCodeBuild功能。

Limitations

packngo函数

For information about limitations that apply to this function, seepackNGo

Executable File with Nondefault Extension

If a build process uses the template makefile approach, thenpackNGouses the executable file extension specified by the linker tool to determine binary artifacts that require packaging.

如果您生成具有默认值的扩展名的可执行文件,请检查扩展名是否保存在与模板makefile关联的工具链中。有关更多信息,请参阅将模板makefile与工具链相关联

If the build process generates an executable file with an extension that is different from the extension saved in the toolchain,packNGo不包装可执行文件。

也可以看看

|

Related Topics