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 Code to Another Development Environment (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 model by running the following command in the MATLAB command prompt.


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.

  3. In the Zip file name (Simulink Coder) field, enter the name of the zip file in which to package generated code and artifacts for relocation. In this example, the name of the zip file is You can specify the file name with or without the .zip extension. If you specify no extension or an extension other than .zip, the zip utility adds extension. If you do not specify a value, the build process uses the name, where model is the name of the top model for which code is being generated.

  4. 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 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.

  5. 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