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
到包装生成的代码:
In the Configuration Parameters dialog box, selectPackage code and artifacts。This option configures the build process to run the
packNGo
代码生成后的功能。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 name
,,,,wheremodel
。压缩
is the name of the top model.model
Apply the changes and then generate code for your model.
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
功能创建两个级别zip
files, a primaryzip
文件又包含以下次要zip
文件:
mlrfiles.zip
- 您的文件
folder treematlabroot
sDirFiles.zip
- 您的构建文件夹中的文件和下方的文件在其中启动了模型的代码生成其他files.zip
- 所需的文件不在
ormatlabroot
开始
folder trees
次要的路径zip
文件相对于主文件夹zip
文件,维护源开发文件夹结构。
Select a Name for the Zip File
默认情况下,packNGo
function names the primaryzip
file
。You have the option of specifying a different name. If you specify a file name and omit the file type extension, the function appendsmodel
。
您指定的名称。
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, use
set_param
to 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 the
packNGo
功能。例如:。。。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'); |
重命名初选zip file |
Packngo(buildInfo,'filename''zippedsrcs'); |
Change the structure of the file packaging to hierarchical and rename the primaryzip file |
packNGo(buildInfo, 'packType' 'hierarchical'... |
在包含路径上找到的标题文件zip file |
Packngo(buildInfo,“ minimalheaders'false); |
Generate warnings for parse errors and missing files | packngo(buildinfo,'ignoreParseError'true ... |
笔记
这packNGo
function can modify the build information in thertw.buildinfo
作为函数的第一个参数传递的对象。该函数可能会从源中找到其他文件,并包括在模型的构建信息中记录的路径,并将该信息添加到rtw.buildinfo
object.
检查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
:
Set your working folder to a writable folder.
Open the model
rtwdemo_rtwintro
并将副本保存到工作文件夹中。In the Command Window, enter:
set_param('rtwdemo_rtwintro',,,,'PostCodeGenCommand',,,,...'packngo(buildInfo,''packType'''''''''')'');
为模型生成代码。
检查生成的zip文件,
rtwdemo_rtwintro.zip
。zip文件包含两个辅助zip文件,mlrfiles.zip
andsDirFiles.zip
。检查
mlrfiles.zip
andsDirFiles.zip
。将ZIP文件重新放置到您的目标文件夹,然后打开包装。
To compile the unpacked code, use the
CodeBuild
功能。
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, thenpackNGo
uses 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
不包装可执行文件。