slbuild
Build standalone executable file or model reference target for model
Syntax
Description
slbuild(
builds a standalone
Simulink®
Coder™ binary executable file from the specified model, using the current
configuration parameter settings. If the model is not loaded,
model
)slbuild
loads the model before starting the build
process.
slbuild(
builds a standalone Simulink
Coder binary executable file from the model as specified by one or more
name-value arguments.model
,Name,Value
)
generates subsystem code and builds a Simulink
Coder binary executable file by using the current configuration
parameter settings of your model. If the selected system target file creates an
S-Function block, the function returns a non-empty block handle to an
autogenerated S-Function wrapper. Before you run the command, you must open or
load the parent model.blockHandle
= slbuild(subsystem
)
generates code from the subsystem that includes function calls that you can export to
external application code. This command requires Embedded Coder®. If the Create block configuration parameter is set to
blockHandle
= slbuild(subsystem
,'Mode','ExportFunctionCalls')SIL
, the function returns the handle to a
Model block in SIL mode. You can then use the Model block
for numerical equivalence testing.
generates subsystem code and builds a Simulink
Coder binary executable file as specified by one or more name-value
arguments.blockHandle
= slbuild(subsystem
,Name,Value
)
Examples
Generate Code and Build Executable File for Model
Generate C code for model
CounterModel
.
openExample('CounterModel') slbuild('CounterModel') % Same operation as ... % slbuild('CounterModel','StandaloneCoderTarget')
For the generic real-time (GRT) target, the coder generates these code
files and places them in folders CounterModel_grt_rtw
and
slprj/grt/_sharedutils
.
Model Files | Shared Files | Interface Files | Other Files |
---|---|---|---|
|
|
| none |
If the following model configuration parameters settings apply, the coder generates additional results.
Parameter Setting | Results |
---|---|
Code Generation > Generate code only pane is cleared | Executable file
CounterModel.exe |
Code Generation > Report > Create code generation report is selected | Report appears, providing information and links to generated code files, subsystem and code interface reports, entry-point functions, inports, outports, interface parameters, and data stores |
Build Multiple Models
This example shows how to use slbuild
to
generate executable code for two models, CounterModel
and
ParallelBuildA1
. ParallelBuildA1
is a
top model that references models and is configured to build the referenced
models in parallel.
Open the models.
openExample("simulinkcoder/RegisterAndUseToolchainToBuildExecutableExample", ... supportingfile="CounterModel.slx") openExample("simulinkcoder/MonitorBuildProcessForModelHierarchyExample", ... supportingfile="ParallelBuildA1.slx")
Build the models.
slbuild({'CounterModel', 'ParallelBuildA1'})
### Starting build procedure for: CounterModel ### Successful completion of build procedure for: CounterModel Build Summary Top model targets: Model Build Reason Status Build Duration =============================================================================================================== CounterModel Information cache folder or artifacts were missing. Code generated and compiled. 0h 0m 37.136s 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 40.889s ### Searching for referenced models in model 'ParallelBuildA1'. ### Found 3 model reference targets to update. Starting parallel pool (parpool) using the 'Processes' profile ... Connected to parallel pool with 4 workers. ### Initializing workers for parallel model reference build. ### Parallel worker initialization complete. ### Starting parallel model reference code generation build. ### Successfully updated the model reference code generation target for: ParallelBuildB1 ### Successfully updated the model reference code generation target for: ParallelBuildB2 ### Successfully updated the model reference code generation target for: ParallelBuildB3 ### Starting build procedure for: ParallelBuildA1 ### Successful completion of build procedure for: ParallelBuildA1 Build Summary Model reference code generation targets: Model Build Reason Status Build Duration ======================================================================================================== ParallelBuildB1 Target (ParallelBuildB1.c) did not exist. Code generated and compiled. 0h 0m 53.995s ParallelBuildB2 Target (ParallelBuildB2.c) did not exist. Code generated and compiled. 0h 0m 53.985s ParallelBuildB3 Target (ParallelBuildB3.c) did not exist. Code generated and compiled. 0h 0m 53.985s Top model targets: Model Build Reason Status Build Duration ================================================================================================================== ParallelBuildA1 Information cache folder or artifacts were missing. Code generated and compiled. 0h 0m 18.998s 4 of 4 models built (0 models already up to date) Build duration: 0h 3m 15.417s
For each model, the build process displays a build summary.
In the current folder, the build process creates standalone executable
files, CounterModel.exe
and
ParallelBuildA1.exe
.
Force Top Model Build
Generate code and build an executable file for the model
TopModelCode
, which refers to model
ReferenceModelCode
, regardless of model checksums and
parameter settings.
openExample('simulinkcoder/FilePackagingModelsCodeAndDataExample',... 'supportingFile','TopModelCode'); slbuild('TopModelCode','StandaloneCoderTarget',... 'ForceTopModelBuild',true)
Generate Code and Build Executable File for Subsystem
Generate C code for subsystem Amplifier
in
model CounterModel
.
openExample('CounterModel') slbuild('CounterModel/Amplifier')
The code generator produces code files in the
Amplifier_grt_rtw
and
slprj/grt/_sharedutils
folders.
In your current working folder, the build process creates an executable
file (Amplifier.exe
).
Build Subsystem for Exporting Code to External Application
To export function calls to external application code, build an executable file from a function-call subsystem.
openExample('SimulinkFunctions') set_param('SimulinkFunctions','GenCodeOnly','off'); slbuild('SimulinkFunctions/util','Mode','ExportFunctionCalls')
The executable file util.exe
appears in your working
folder.
Create Model Block for SIL Testing
From a function-call subsystem, create a Model block that you can use to test the code generated from a model.
Open subsystem util
in model
SimulinkFunctions
.
Set the Code Generation > Verification > Advanced parameters > Create block configuration parameter to SIL
.
Create the Model block.
openExample('SimulinkFunctions'); set_param('SimulinkFunctions','GenCodeOnly','off'); mysilblockhandle = slbuild('SimulinkFunctions/util',... 'Mode','ExportFunctionCalls')
The code generator produces the Model block in a temporary model. The Model block is configured as follows:
Model name is set to the name of a new model that contains the content of the original subsystem.
Simulation mode is set to
Software-in-the-loop (SIL)
.
You can add the block to an environment or test harness model that supplies test vectors or stimulus input. You can then run simulations that perform SIL tests and verify that the Model block produces the same result as the original subsystem.
Input Arguments
model
— Specifies model for the build process
handle | character vector | cell array of handles or character vectors
If you specify the model name as a handle or character vector, the build process creates a standalone executable file or model reference target.
If you specify multiple models through a cell array of handles or
character vectors, the build process applies buildSpec
to each model in the cell array.
Example: gcs
subsystem
— Subsystem name
handle | character vector | cell array of handles or character vectors
Name of subsystem from which you want to generate code or build an executable file, specified as a handle or character vector representing the subsystem name or the full block path.
You can specify multiple subsystems through a cell array of handles or character vectors
Example: 'SimulinkFunctions/util'
buildSpec
— Specifies the code generation action for the build process
'StandaloneCoderTarget'
| 'ModelReferenceCoderTarget'
| 'ModelReferenceSimTarget'
| 'CleanTopModel'
buildSpec
directs the code generator to perform the
selected build action for the model and the build process:
Honors the setting of the Rebuild parameter on the Model Referencing pane of the Configuration Parameters dialog box.
Requires a Simulink Coder license only if you build a model reference Simulink Coder target, not if you build a model reference simulation target only.
The buildSpec
argument must be one of the
following.
buildSpec Value | Build Action | Notes |
---|---|---|
| Builds a standalone Simulink Coder binary executable file for the specified model, using the current model configuration settings. It also builds model reference coder targets for the referenced models. If the specified model is
not loaded, |
|
| Builds a model reference Simulink Coder target. |
|
| Builds a model reference simulation target. | Does not require a Simulink Coder license. |
| Cleans the model build area enough to trigger regeneration of the top model code at the next build. | You cannot specify this value when you select Component or Subcomponent from the Deployment Type menu. |
Example: 'ModelReferenceSimTarget'
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: 'UpdateThisModelReferenceTarget','Force'
UpdateThisModelReferenceTarget
— Conditional rebuild option for model reference build
'Force'
| 'IfOutOfDateOrStructuralChange'
| 'IfOutOfDate'
Conditional rebuild option for the model reference build, specified as
the comma-separated pair consisting of
'UpdateThisModelReferenceTarget'
and
'Force'
,
'IfOutOfDateOrStructuralChange'
, or
'IfOutOfDate'
.
This option applies only to the specified model, not to any models referenced by the specified model.
'UpdateThisModelReferenceTarget' Value | Equivalent Rebuild Option | Rebuild Action |
---|---|---|
| Always | Unconditionally rebuilds the model. |
| If changes
detected | Rebuilds the model if the build process detects any changes. |
| If changes in known dependencies
detected | Rebuilds the model if the build process detects any changes in known dependencies of this model. |
For more information on the different rebuild options, see Rebuild.
Example: 'UpdateThisModelReferenceTarget','Force'
Dependencies
To use this option, set buildSpec
to
'ModelReferenceSimTarget'
or
'ModelReferenceCoderTarget'
.
Data Types: char
| string
BuildOutputType
— Build output type
'Auto' (default) | 'Executable'
| 'StaticLibrary
| 'SharedLibrary'
If your top model uses an ERT or GRT system target file, use this option to specify the output type for the build process.
'BuildOutputType' Value | Build Action |
---|---|
| In the code generation folder, create a Simulink Coder binary file from the top model. The output type of the build process depends on the current configuration parameter settings. For example:
|
| In the code generation folder, create a standalone
Simulink
Coder binary executable file from the top-model
generated code. For example,
myModel.exe . |
| In the build folder, create a static library
from the top-model generated code. For example,
|
| In the build folder, create a shared library
from the top-model generated code. For
example, |
For information about code generation and build folders, see Manage Build Process Folders (Simulink Coder).
Example: 'BuildOutputType'
,'StaticLibrary'
Dependencies
To use this option, set buildSpec
to
'StandaloneCoderTarget'
.
Data Types: char
| string
ForceTopModelBuild
— Force top model of model hierarchy to build
false
(default) | true
Option to force the top model of the model hierarchy to build,
specified as the comma-separated pair consisting of
'ForceTopModelBuild'
and true
or false
.
Setting the value to true
directs the code
generator to generate code and build an executable file for the top
model of the model hierarchy, regardless of model checksums and
parameter settings.
Example: 'ForceTopModelBuild',true
Dependencies
To use this option, set buildSpec
to
'StandaloneCoderTarget'
.
Data Types: logical
GenerateCodeOnly
— Generate code only
false
| true
If you do not specify a value, the Generate code
only (GenCodeOnly
) option on the
Code Generation pane controls build process
behavior.
If you specify a value, the argument overrides the Generate
code only (GenCodeOnly
) option on the
Code Generation pane:
true
–– Generate code only.false
–– Generate code and build executable file.
Mode
— Export function calls (for subsystem builds only)
'ExportFunctionCalls'
| 'Normal'
'ExportFunctionCalls'
–– If you have Embedded Coder, generates code fromsubsystem
that includes function calls that you can export to external application code.'Normal'
–– Does not export function calls.
ExportFunctionFileName
— Function name
character vector
Name the exported function for the specified subsystem.
Example: slbuild(
subsystem
,'Mode','ExportFunctionCalls','ExportFunctionFileName',
fcnname
)
ExportFunctionInitializeFunctionName
— Function name
character vector
Name the exported initialization function for specified subsystem.
Example: rtwbuild(
subsystem
,'Mode','ExportFunctionCalls','ExportFunctionInitializeFunctionName',
fcnname
)
OpenBuildStatusAutomatically
— Display build information
false
(default) | true
Option to display the build information, specified as the
comma-separated pair consisting of
'OpenBuildStatusAutomatically'
and
true
or false
.
To display build information in the Build Status window, specify
true
. The default is false
.
For more information about using the status window, see Monitor Parallel Building of Referenced Models (Simulink Coder).
The Build Status window supports parallel builds of referenced model hierarchies. Do not use the Build Status window for serial builds.
Dependencies
To use this option, set buildSpec
to
'StandaloneCoderTarget'
.
Data Types: logical
ObfuscateCode
— Generate obfuscated C code
false
(default) | true
Specify whether to generate obfuscated C code:
true
–– Generate obfuscated C code that you can share with third parties with reduced likelihood of compromising intellectual property.false
–– Generated C code is not obfuscated.
Output Arguments
blockHandle
— Block handle
handle
Block handle to an autogenerated S-Function wrapper block or Model block.
Extended Capabilities
Automatic Parallel Support
Accelerate code by automatically running computation in parallel using Parallel Computing Toolbox™.
To build referenced models in parallel, in the top model, select the configuration parameter check box Enable parallel model reference builds. For more information, see Reduce Build Time for Referenced Models by Using Parallel Builds (Simulink Coder).
In Parallel Computing Toolbox™ commands, for example, a parfor
or spmd
loop, do not invoke rtwbuild
, rtwrebuild
, or
slbuild
commands that build models that are configured for parallel
builds.
Version History
Introduced before R2006aR2024b: IncludeModelReferenceSimulationTargets
argument will not be supported
The slbuild
function issues a warning when you use the
IncludeModelReferenceSimulationTargets
argument. The
warning indicates that the argument has no effect and will be removed in a future
release.
R2020b: slbuild
does not generate model reference simulation targets by default
The slbuild
function no longer generates model reference
simulation targets by default. Excluding the model reference simulation targets
allows for faster code generation for model hierarchies.
When you specify 'ModelReferenceCoderTarget'
for the
buildSpec
argument, slbuild
no longer
builds a model reference simulation target. It builds only a model reference
Simulink
Coder target.
R2020b: 'ModelReferenceCoderTargetOnly'
is not recommended
The buildSpec
argument values
'ModelReferenceCoderTarget'
and
'ModelReferenceCoderTargetOnly'
now have the same behavior.
'ModelReferenceCoderTargetOnly'
is not recommended. Use
'ModelReferenceCoderTarget'
instead.
There are no plans to remove
'ModelReferenceCoderTargetOnly'
.
R2019a: 'StandaloneRTWTarget'
, 'ModelReferenceRTWTarget'
, and
'ModelReferenceRTWTargetOnly'
are not recommended
These buildSpec
argument values received new names for clarity:
'StandaloneRTWTarget'
— Use'StandaloneCoderTarget'
instead.'ModelReferenceRTWTarget'
— Use'ModelReferenceCoderTarget'
instead.'ModelReferenceRTWTargetOnly'
— Use'ModelReferenceCoderTargetOnly'
instead.
There are no plans to remove the legacy buildSpec
argument
values.
See Also
codebuild
(Simulink Coder) | rtwrebuild
(Simulink Coder)
Topics
- Manage Simulation Targets for Referenced Models
- What Is Acceleration?
- Perform Acceleration
- Share Simulink Cache Files for Faster Simulation
- Build and Run a Program (Simulink Coder)
- Approaches for Building Code Generated from Simulink Models (Simulink Coder)
- Reduce Build Time for Referenced Models by Using Parallel Builds (Simulink Coder)
- Control Regeneration of Top Model Code (Simulink Coder)
- Generate Component Source Code for Export to External Code Base (Embedded Coder)
- Test Generated Code with SIL and PIL Simulations (Embedded Coder)
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)