Main Content

Code Generation Basics

Overview and initiation of code generation

The basic steps for producing code with the code generator are:

  • Open a model

  • Configure the model for code generation by selecting the target, the language, and the code generation objectives

  • Select the build approach (for example, toolchain approach)

  • Build the model

The model configuration parameters provide many options for the code generation and build process.


expand all

crossReleaseImportImport generated model code from a previous release as SIL or PIL blocks
pil_block_replaceReplace block in model with block from another model
sharedCodeMATLABVersionsManage MATLAB versions for cross-release code integration
sharedCodeUpdateAdd new shared code source files to existing shared code folder


Embedded CoderGenerate readable, compact, and fast C and C++ code for embedded processors used in mass production


Getting Started

Generate Code by Using the Quick Start Tool

Prepare a model for quickly generating readable, efficient code.

Check Model and Configuration for Code Generation

Assess model readiness to generate code by using the Model Advisor and Code Generation Advisor.

Generate Code Using Embedded Coder®

Select a target for a Simulink® model, configure options, generate C code for embedded systems, and view generated files.

Aircraft Position Radar Model

This model shows the code generated for a Simulink model containing a MATLAB script.

Code Generation Files and Folders

Manage Build Process Folders

Manage folders that the code generator creates.

Manage Build Process Files

Work with generated source files and dependency files that the code generator produces.

Manage Build Process File Dependencies

Work with generated source files and dependency files that the code generator produces.

Add Build Process Dependencies

Add dependency information for external code to the build process.

Build Process Support for Folder Names with Spaces or Special Characters

Troubleshoot build process errors that occur when file system issues prevent file processing.

Manage File Packaging of Generated Code Modules

Generate code modules and header files with the code generator.

Options for More Code Generation Control

Cross-Release Code Integration

Integrate generated code from previous releases with generated code from current release.

Integrate Generated Code by Using Cross-Release Workflow

Reuse previously generated code by using a cross-release SIL block in an integration model.

Use Protected Models from Previous Releases to Perform SIL Testing and Generate Code

Integrate generated code from protected models created in previous releases.

Integration of Code from Multiple Folders

Integrate separately generated code.

Internationalization and Code Generation

Internationalization support for enabling efficient globalization.

Code Generation with Project

Generate Code and Simulate Models in a Project

This example shows how to use the code generation template for a new Project.

Generate Code and Simulate Models Programmatically with Project

This example shows how to use the Project API to create a new project and automate project tasks for manipulating files.

Embedded System Code Generation Tutorial

Tutorial for Generating C Code from a Control Algorithm for an Embedded System

This guided tutorial shows how to generate code for a control algorithm model, integrate the generated code with an existing system, and validate simulation and executable results.