Package Code for Other Development Environments - MATLAB & Simulink (original) (raw)

Main Content

When to Package Code

To relocate the generated code files to another development environment, such as a system or an integrated development environment (IDE) that does not include MATLAB®, use the packNGo function at the command line or theExport > Package Generated Code as a ZIP File button in theMATLAB Coder™ app. The files are packaged in a compressed file that you can relocate and unpack using a standard zip utility.

Package Generated Code by Using the MATLAB Coder App

This example shows how to package generated code into a zip file for relocation using the Export button in the MATLAB Coder app. By default, MATLAB Coder creates the zip file in the current working folder.

  1. In a local writable folder, for example c:\work, write a functionfoo that takes two double inputs.
    function y = foo(A,B)
    y = A + B;
    end
  2. Open the MATLAB Coder app from the Apps tab on the MATLAB Toolstrip.
  3. In the Create MATLAB Coder Project dialog box, specify a name for your project. For this example, enter foo.coderprj. The app creates the project file in the working folder.
  4. Open the Entry Points pane by clicking the Entry Points button on the MATLAB Coder tab of the toolstrip. Enter foo as the name of the entry-point function. Specify that inputs A and B are scalar doubles. See Define Types of Entry-Point Inputs by Using the MATLAB Coder App.
  5. You cannot package the code generated for MEX targets. To configure the app to generate standalone code, click Output Type in the MATLAB Coder tab of the toolstrip. Then, select Static Library (.lib), Dynamic Library (.dll), orExecutable (.exe).
  6. On the MATLAB Coder tab of the toolstrip, click Generate Code.
  7. To export the generated code as a single flat file, on the MATLAB Coder tab of the toolstrip, click Export > Package as a Flat ZIP File. Specify a name for the zip file. For this example, enterfoo_pkg.zip.
    This zip file contains the C code and header files required for relocation. It does not contain:
  8. Inspect the contents of foo_pkg.zip in your working folder to verify that it is ready for relocation to the destination system. Depending on the zip tool that you use, you can potentially open and inspect the file without unpacking it.
    You can now relocate the resulting zip file to the desired development environment and unpack the file.

Package Generated Code at the Command Line

This example shows how to package generated code into a zip file for relocation using the packNGo function at the command line.

  1. In a local writable folder, for example c:\work, write a function foo that takes two double inputs.
    function y = foo(A,B)
    y = A + B;
    end
  2. Generate a static library for function foo. (packNGo does not package MEX function code.)
    codegen -report -config:lib foo -args {0,0}
    codegen generates code in the c:\work\codegen\lib\foo folder.
  3. Load the buildInfo object.
    load('c:\work\codegen\lib\foo\buildInfo.mat')
  4. Create the zip file.
    packNGo(buildInfo, 'fileName', 'foo.zip');
    Alternatively, use the notation:
    buildInfo.packNGo('fileName', 'foo.zip');
    ThepackNGo function creates a zip file, foo.zip, in the current working folder. This zip file contains the C code and header files required for relocation. It does not contain:
  5. Inspect the contents of foo.zip to verify that it is ready for relocation to the destination system. Depending on the zip tool that you use, you can potentially open and inspect the file without unpacking it. If you need to unpack the file and you packaged the generated code files as a hierarchical structure, you will need to unpack the primary and secondary zip files. When you unpack the secondary zip files, relative paths of the files are preserved.

You can now relocate the resulting zip file to the desired development environment and unpack the file.

Specify packNGo Options

You can specify options for the packNGo function.

To Specify
Change the structure of the file packaging to hierarchical packNGo(buildInfo, 'packType' 'hierarchical');
Change the structure of the file packaging to hierarchical and rename the primary zip file packNGo(buildInfo, 'packType' 'hierarchical'...'fileName' 'zippedsrcs');
Include all header files found on the include path in the zip file (rather than the minimal header files required to build the code) packNGo(buildInfo, 'minimalHeaders' false);
Generate warnings for parse errors and missing files packNGo(buildInfo, 'ignoreParseError' true...'ignoreFileMissing' true);

For more information, see packNGo.

Choose a Structure for the Zip File

Before you generate and package the files, decide whether you want to package the files in a flat or hierarchical folder structure. By default, thepackNGo function packages the files in a single, flat folder structure. This approach is the simplest and might be the optimal choice.

If Use
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 A single, flat folder structure
The target development environment must maintain the folder structure of the source environment because it uses the generated makefile, or the code is dependent on the relative location of files A hierarchical structure

If you use a hierarchical structure, the packNGo function creates two levels of zip files. There is 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.