Relocate or Share Generated Code
To relocate or share static and generated code files, you can use the packNGo
function. For example, use the function when you want to
relocate generated code to a development environment that does not provide MATLAB® and Simulink® products.
Package and Relocate Generated Code
To package generated code:
Open the Configuration Parameters dialog box. On the Code Generation pane, in the Build Process section, select Package code and artifacts. This option configures the build process to run the
packNGo
function after code generation.Point to the three dots at the bottom of the Configuration Parameters dialog box and click Advanced parameters.
Under Advanced parameters, in the Zip file name box, enter the name of the ZIP file in which to package the generated code and artifacts. If you specify the file name without the
.zip
extension, it is added automatically. If you do not specify a name for the ZIP file, the software uses the name
, wheremodel
.zip
is the top model name.model
Click Apply.
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 provides Simulink
Coder™ or Embedded Coder®, you can use codebuild
to compile the unpacked code.
Package and Relocate Generated Code From Command Line
To package and relocate generated code by using line commands, use this workflow:
Select a Structure for the ZIP File
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, the packNGo
function packages the
files in a single, flat folder structure.
If... | Then Use a... |
---|---|
You are relocating files to an IDE that does not use the generated makefile, or the code is not dependent on the relative location of required static files | Single, flat folder structure |
The 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 | Hierarchical structure |
If you use a hierarchical structure, the packNGo
function creates two
levels of zip
files, a primary zip
file,
which in turn contains the following secondary zip
files:
mlrFiles.zip
— Files located beneathmatlabroot
sDirFiles.zip
— Files located beneath the code generation folderotherFiles.zip
— Required files that are not located beneath
or the code generation foldermatlabroot
Paths for the secondary zip
files are relative to the root
folder of the primary zip
file, maintaining the source
development folder structure.
Select Name for ZIP File
By default, the packNGo
function names the primary
zip
file
. You have the option of
specifying a different name. If you specify a file name and omit the file type
extension, the function appends model
.
to the name that you
specify.
Package Generated Code in ZIP File
Package generated code files by using the packNGo
function and build information object for the model. You can use:
A system-generated
buildInfo.mat
file. See Code Packaging Example.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
function. For example:. . . myModelBuildInfo = RTW.BuildInfo; addSourceFiles(myModelBuildInfo, {'test1.c' 'test2.c' 'driver.c'}); . . . packNGo(myModelBuildInfo);
The following examples show how you can change the default behavior of
packNGo
.
To... | Specify... |
---|---|
Change the structure of the file packaging to hierarchical | packNGo(buildInfo, 'packType'
'hierarchical'); |
Rename the primary zip file | packNGo(buildInfo, 'fileName'
'zippedsrcs'); |
Change the structure of the file packaging to hierarchical
and rename the primary zip file | packNGo(buildInfo, 'packType'
'hierarchical'... |
Include header files found on the include path in the
zip file | packNGo(buildInfo, 'minimalHeaders'
false); |
Generate warnings for parse errors and missing files | packNGo(buildInfo, 'ignoreParseError'
true... |
Note
The packNGo
function can modify
the build information in the RTW.BuildInfo
object that is
passed as the first argument of the function. The function might find
additional files from source and include paths recorded in build information
for the model and add that information to the
RTW.BuildInfo
object.
Inspect Generated ZIP File
To verify that the generated ZIP file is ready for relocation, use a ZIP tool to inspect the file. Some ZIP tools allow you to view the file contents without unpacking the file. If unpacking is required and the model code files are packaged as a hierarchical structure, you have to unpack the primary and secondary ZIP files. When you unpack the secondary ZIP files, relative paths of the files are preserved.
Relocate and Unpack 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 provides Simulink
Coder or Embedded Coder, you can use codebuild
to compile the unpacked code.
Code Packaging Example
This example shows how to package code files generated from the model
CounterModel
.
Open the model.
openExample('CounterModel');
Generate code for the model. In the Command Window, enter:
slbuild(gcs)
Specify the path to the build information object.
buildInfoFile = fullfile('CounterModel_ert_rtw','buildInfo.mat');
Run the
packNGo
function.packNGo(buildInfoFile,packType="allHierarchical", ... includeReport=true);
Inspect the generated ZIP file,
CounterModel.zip
. The ZIP file contains a secondary ZIP file,sDirFiles.zip
.Inspect
sDirFiles.zip
.Relocate the ZIP file to your destination folder and unpack it.
To compile the unpacked code, use the
codebuild
function.
Limitations
packNGo Function
For information about limitations that apply to this function, see packNGo
.
Executable File with Nondefault Extension
If a build process uses the template makefile approach, then packNGo
uses the executable file
extension specified by the linker tool to determine binary artifacts that
require packaging.
If you generate an executable file with an extension that is not a default value, check that the extension is saved in the toolchain associated with the template makefile. For more information, see Associate the Template Makefile with a Toolchain.
If the build process generates an executable file with an extension that is
different from the extension saved in the toolchain, packNGo
does not package the executable file.