Relocate or Share Generated Code - MATLAB & Simulink (original) (raw)

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:

  1. 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.
  2. Point to the three dots at the bottom of the Configuration Parameters dialog box and click Advanced parameters.
  3. 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_`model`_.zip, where_`model`_ is the top model name.
  4. Click Apply.

Configuration Parameters dialog box. The Parameter Package code and artifacts is selected and a filename is specified for Zip file name.

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:

  1. Select a structure for the zip file.
  2. Select a name for thezip file.
  3. Package the model code files in the zip file.
  4. Inspect the generatedzip file.
  5. Relocate and unpack thezip file.

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:

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 primaryzip file_`model`_. You have the option of specifying a different name. If you specify a file name and omit the file type extension, the function appends . 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:

The following examples show how you can change the default behavior ofpackNGo.

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'...'fileName' 'zippedsrcs');
Include header files found on the include path in thezip file packNGo(buildInfo, 'minimalHeaders' false);
Generate warnings for parse errors and missing files packNGo(buildInfo, 'ignoreParseError' true...'ignoreFileMissing' 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 theRTW.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 modelCounterModel.

  1. Open the model.
    openExample('CounterModel');
  2. Generate code for the model. In the Command Window, enter:
  3. Specify the path to the build information object.
    buildInfoFile = fullfile('CounterModel_ert_rtw','buildInfo.mat');
  4. Run the packNGo function.
    packNGo(buildInfoFile,packType="allHierarchical", ...
    includeReport=true);
  5. Inspect the generated ZIP file, CounterModel.zip. The ZIP file contains a secondary ZIP file,sDirFiles.zip.
  6. Inspect sDirFiles.zip.
  7. Relocate the ZIP file to your destination folder and unpack it.
  8. 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.

See Also

packNGo | codebuild

Topics