Build Application Code
R2026bMultiple approaches are available for building service-oriented architecture application code. The approach you choose depends on whether you are developing an application or a system architecture consisting of one or more applications. The approach also depends on available or preferred tooling approaches.
Choose an Approach to Build Application Code
To build your application code, choose one of these approaches:
| Build Approach | Reasons to Choose |
|---|---|
| Generate source code only |
|
| Build generated source code outside of the MATLAB® environment (algorithm export) | Build and integrate generated component source code outside of the MATLAB environment for conducting component verification. |
| Build application as a top model and standalone unit | Build an executable program for the component as a top model for conducting component verification. |
| Build application for software-in-the-loop (SIL) simulation | Test for numerical equivalence between normal mode simulation results and simulation of generated component code. |
| Build application in the context of a system | Generate and build component code after integrating the components into an architecture model representing a system. |
| Build application by using a Docker container | Provide an environment that is preconfigured with the toolchain, libraries, and platform dependencies required to compile and run the application onLinux® . Monitor and tune application signals and parameters if configured to use external mode or a Universal Measurement and Calibration Protocol (XCP) server. |
Application Build Configuration and Startup
Use this table as a guide for configuring and starting a build depending on the build approach that you choose.
| Build Approach | Configuration Options | Build Environment and Tooling Options | Run-Time Environment Options | Other Notes | |||||
|---|---|---|---|---|---|---|---|---|---|
| Generate source code only |
| On the development computer:
Use the |
|
| |||||
| Build generated source code outside of the MATLAB environment (algorithm export) |
| On the development computer:
Use the |
|
| |||||
| Build application as a top model and standalone unit |
| On the development computer:
Use the |
|
| |||||
| Build application for software-in-the-loop (SIL) simulation |
| On the development computer:
|
| ||||||
| Build application in the context of a system |
| On the development computer, with the architecture model selected:
Use the |
| ||||||
| Build application by using a Docker container |
| On development computer, use the Linux Runtime Manager. |
| The Runtime Manager simplifies building, packaging, deploying, and running application software as a system. |
Additional points to consider depending on your choices from the preceding table:
For builds in the MATLAB environment:
Set the Toolchain parameter to a value that includes CMake or
gmake.
For builds outside of the MATLAB environment, for each software component model:
Run CMake in the generated folder
orapplication-name/exe. CMake processes files in other folders automatically. If you build in theapplication-name/libfolder, the build produces a library instead of an executable program.application-name/libIf you run CMake in the
folder after running it inapplication-name/exe, the build replaces the existing library file with a new intermediate version.application-name/lib
For manual
gmakebuilds:For each software component model, execute the command
gmake -ffor each of these folders in the folder order shown:makefilenameEach
folderapplication-name/subcomponent-namefolderapplication-name/shared/libfolderapplication-name/application/libfolderapplication-name/exe
For builds when the Toolchain parameter is set to
GNU gcc/g++ | CMake/gmake (64-bit Linux):You can start a build by pressing CTRL+B or by using the
slbuildfunction.If Generate code only is selected, and you want to build manually, for each software component model, run CMake in each of these folders in the order shown:
Each
folderapplication-name/subcomponent-namefolderapplication-name/shared/libfolderapplication-name/application-name/libfolderapplication-name/exe
This results in an executable program build linking against the same library as a build for SIL simulation.
On Linux, for each application, the build process creates a shell script that lists CMake commands relevant for that folder.
Build Process Folder and File Structure and Naming
The build process places and names generated files in a default folder and file structure. Content of the structure varies depending on the build approach that you use. For example, if you generate source code only from a software component model, the structure only includes folders and files relevant for that application.
Default Folder and File Structure and Naming
For the most comprehensive build process, building an application in the context of a system, the code generator creates a folder that has the name of the architecture model. That folder stores application execution scheduling and service instance configuration manifest files. The manifest files are organized in a folder for each application (software component).
For example:
architecture-name application-name-1 application-name-2 application-name-3
These manifest files are in each application folder:
ExecutionManifest.jsonServiceInstanceManifest.json
For each software component model in the architecture model, the code generator creates a folder in your MATLAB® current folder for storing files that it generates for the application. This table lists paths for folders and files that the code generator creates.
| Folder | Content |
|---|---|
| Build configuration files, such as buildinfo.mat and
code descriptor codedescriptor.dmr, and the algorithm and
service interface source (.cpp) and header
(.h) files |
| Executable program file and Make, data, and library files for building the executable |
| Algorithm library and data files |
| Shared utility source files |
| Library built from the source files in
|
The files and
application-name.h in folder
application-name.cpp
declare and define application entry-point functions, which are called from other
application code. For example:application-name/application-name
software-component-name_initializesoftware-component-name_terminatesoftware-component-name_step(exported)software-component-name_subsystem-name
These functions exchange data with target application code through service interfaces. The corresponding header files declare interfaces that the algorithm entry-point functions use to call other applications.
Customize Folder and File Structure and Naming
During a build, the code generator and build process place generated files into a default hierarchy of folders. Change the default structure and naming if:
You do not want to use the current working folder as the location for the code generation folder or the simulation cache folder.
You place the code generation folder under version control, but do not place the simulation cache folder under version control.
MATLAB session parameters are available for customizing the structure and naming.
Parameters CacheFolder and CodeGenFolder are file
generation control parameters that specify the folder locations for the build process.
At the start of a MATLAB session, these Simulink settings determine the values of the parameters:
| MATLAB Session Parameter | Simulink Preference | Description |
|---|---|---|
CacheFolder | Simulation cache folder | Defines the root folder for simulation artifacts (for example, for Stateflow® and accelerator mode simulation ), and the Simulink cache file.
By
default, when you set ( You can use the parameter to specify another folder. For example, if you want to:
|
CodeGenFolder | Code generation folder | Defines the root folder for generated code.
You can use the parameter to specify another folder. For example, if you want to separate generated production code from:
If you specify the root folder of a drive (for example,
|
Note
The MATLAB session parameter CodeGenFolderStructure and the
Simulink preference Code generation folder structure are not
supported for models configured to use service interfaces and application
deployment.
If you want the parameter settings to persist across MATLAB sessions, adjust them in
the Simulink Settings dialog box. To modify the parameter settings during a MATLAB
session, use the function Simulink.fileGenControl. Setting changes that you make with the
Simulink.fileGenControl function override the settings in the
Simulink Settings dialog box. The parameter values that the function sets expire at the
end of the MATLAB session.
For more information, see Build Process Support for File and Folder Names.
Application Build Limitation
You must compile generated application code on a Linux system. If you want to generate application code on a Windows development system, build the application by using the Linux Runtime Manager and a Docker container. Then, you can compile the code on a remote Linux development system or a Windows Subsystem for Linux system running an SSH server.
See Also
Hardware
board | Toolchain | Generate code only | Package code and artifacts | Zip file name | packNGo