Main Content

Deploy the C++ Generated Code

In this step of the tutorial, you explore mechanisms for deploying the generated code.

Example Main Program

To facilitate deployment of the generated code, the code generator produces an example main program that you can use to get started. The example main program is in the file ert_main.cpp. To use the C++ class and model entry-point functions generated for your application, you can copy the incomplete functions defined in ert_main.cpp, and then complete the functions by inserting your custom scheduling code.

Explore the example main program generated for model rtwdemo_cppclass_workflow.

  1. If not already open, open your copy of the model rtwdemo_cppclass_workflow.

  2. In the Apps gallery, click Embedded Coder.

  3. Regenerate the code.

  4. In the Code view, select file ert_main.cpp.

  5. Click in the Search field and select function rt_OneStep.

  6. Explore the incomplete wrapper function rt_OneStep. This function calls the model execution entry-point function, step0. Your application code can call rt_OneStep to run the model algorithm during each execution cycle.

  7. Click in the Search field and select function main.

  8. Explore the incomplete example main function. This function outlines the order and context in which your application code can call rt_OneStep and other model entry-point functions.

Overview of Generated Code Files

The code generator creates two folders in your MATLAB® current folder for the generated code files:

  • slprj

  • rtwdemo_cppclass_workflow_ert_rtw

The slprj/ert/_sharedutils folder contains generated files that are shared between multiple models. This folder contains the file rtwtypes.h, which defines standard data types that the generated code uses by default.

The rtwdemo_cppclass_workflow_ert_rtw folder contains the model-specific files of your generated code, including the two primary files rtwdemo_cppclass_workflow.cpp and rtwdemo_cppclass_workflow.h.

Relocate Generated Code Files

Embedded Coder® provides a packNGo utility for relocating static and generated code files for a model to another development environment. The utility packages the files in a compressed file that you can relocate and unpack by using a standard zip utility. You can apply the packNGo utility from graphical and programming interfaces.

For more information, see Relocate or Share Generated Code.

Share and Archive a Code Generation Report

The Quick Start tool configures a model to produce an HTML code generation report. In addition to a summary of model and code information, the report includes:

  • A subsystem report

  • A code interface report

  • A traceability report

  • A static code metrics report

  • A code replacements report

  • Coder assumptions

  • Generated code files

  • Optionally, a model web view

You can use this report outside of the Simulink® environment, so it is suitable for sharing or for archival purposes. You can open the report from the tool or, on the C++ Code tab, click Open Report.

The default location for the code generation report files is in the html subfolder of the build folder, model_target_rtw/html/. target is the name of the System target file specified on the Code Generation pane. The default name for the top-level HTML report file is index.html.

View of the Code Generation Report for rtwdemo_cppclass_workflow

Explore Other Options

To explore more ways to customize, verify, and deploy generated production code, use the links listed in the table.

TaskReference
Consider model design and configuration for code generationArchitecture and Component Design
Learn about generated entry-point functions

Configure Generated C Function Interface for Model Entry-Point Functions

Learn about configuring C++ code interfaces for code generationInteractively Configure C++ Interface
Achieve code reuseChoose a Componentization Technique for Code Reuse
Compare normal mode simulation results against software-in-the-loop (SIL) or processor-in-the-loop (PIL) simulation results for numeric equivalencySIL and PIL Simulations and Choose a SIL or PIL Approach
Collect code coverage metrics for generated code during SIL or PIL simulationCode Coverage
Use generated example main code as a starting point to deploy generated executable programsDeploy Generated Standalone Executable Programs To Target Hardware

Related Topics