Main Content

Relocate Code Generated from a Simulink Model to Another Development Environment

Once you generate code from your Simulink® model, you can relocate the code to another development environment using the pack-and-go utility. Use this utility when the development environment does not have the MATLAB® and Simulink products.

The pack-and-go utility uses the tools for customizing the build process after code generation and a packNGo (Simulink Coder) function to find and package files for building an executable image. The files are packaged in a compressed file that you can relocate and unpack using a standard zip utility.

You can package the code using either the user interface or the command-line interface. The command-line interface provides more control over the details of code packaging. For more information on each of these methods, see Relocate or Share Generated Code (Simulink Coder).

Package the Code

This example shows how to package the executable generated from the ex_codegen_dsp model in the Generate C Code from Simulink Model example using the user interface. You can also generate and package a static library file or a dynamic library file.

Open the ex_codegen_dsp model in the Generate C Code from Simulink Model example.

To package and relocate code for your model using the user interface:

  1. In the Modeling tab, click Model Settings. The Configuration Parameters dialog opens. Navigate to the Code Generation tab.

  2. To package the executable along with the source code, clear Generate code only check box and select the option Package code and artifacts (Simulink Coder). This option configures the build process to run the packNGo (Simulink Coder) function after code generation to package generated code and artifacts for relocation.

    Snapshot of the Code Generation pane under the model configuration parameters. Under Target selection, System target file is set to grt.tlc, language is set to C. Under Build process, Generate code only parameter is not selected, Package code and artifacts parameter is selected, Toolchain is set to Automatically locate an installed toolchain, and Build configuration is set to Faster Builds. Under Code generation objectives, Select objective is set to Unspecified and Check model before generating code is set to Off.

  3. Click Apply. In the C Code tab of the model toolstrip, click the Build Model icon (). If the C Code tab is not open, in the Apps gallery of the model toolstrip, click Simulink Coder. The C Code tab appears. When you click on the Build Model icon (), the code generator builds the executable, generates the Code Generation Report and places the executable in the current working folder. Note that the build process creates a new subfolder called ex_codegen_dsp_grt_rtw in your current MATLAB working folder. This subfolder contains the generated source code files. In addition, you can also see ex_codegen_dsp.zip file in the current directory. The zip files contains the ex_codegen_dsp_grt_rtw folder, the executable, and other additional dependency source files required to run the executable without Simulink and MATLAB installed.

  4. Relocate the zip file to the destination development environment and unpack the file to run the executable.

Prebuilt Dynamic Library Files (.dll)

If your model contains any blocks mentioned in How To Run a Generated Executable Outside MATLAB, the executable generated from the model requires certain prebuilt dynamic library (.dll) files. These .dll files are shipped with MATLAB. To package code that runs on an environment without MATLAB and Simulink installed, the Simulink Coder™ packages these .dll files into the zip folder.

Related Topics