Build standalone executable or model reference target for model
slbuild(
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.model
)
If the specified model is not loaded, slbuild
loads the
model before initiating the build process.
If the model
argument is a cell array of top models,
slbuild
builds an executable file for each model.
You cannot use slbuild
to build subsystems.
slbuild(___,
builds files based on one or more name-value pair arguments.Name,Value
)
Generate C code for model rtwdemo_rtwintro
.
slbuild('rtwdemo_rtwintro') % Same operation as ... % slbuild('rtwdemo_rtwintro','StandaloneCoderTarget')
For the generic real-time (GRT) target, the coder generates these code
files and places them in folders rtwdemo_rtwintro_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 image
rtwdemo_rtwintro.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 |
This example shows how to use slbuild
to
generate executable code for two models,
sldemo_mdlref_depgraph
and
rtwdemo_counter
.
sldemo_mdlref_depgraph
is a top model that references
models. The example also shows how to build the referenced models in parallel.
Create a local folder.
if exist(fullfile('.','myTempFolder'),'dir') rmdir('myTempFolder','s') end mkdir myTempFolder cd myTempFolder
Copy sldemo_mdlref_depgraph
, which references models,
to the local folder.
src_dir = fullfile(matlabroot, ... 'toolbox', ... 'simulink', ... 'simdemos', ... 'simfeatures', ... 'modelreference'); copyfile(fullfile(src_dir, ... 'sldemo_mdlref_depgraph.slx'), ... '.');
Enable parallel building of models referenced by
sldemo_mdlref_depgraph
.
load_system('sldemo_mdlref_depgraph') set_param('sldemo_mdlref_depgraph', ... 'EnableParallelModelReferenceBuilds', 'on');
Initialize MATLAB® workers for parallel building of referenced models.
set_param('sldemo_mdlref_depgraph', ... 'ParallelModelReferenceMATLABWorkerInit', ... 'Copy Base Workspace');
Build the models.
slbuild({'sldemo_mdlref_depgraph', 'rtwdemo_counter'})
In myTempFolder
, the build process creates standalone
executable files, sldemo_mdlref_depgraph.exe
and
rtwdemo_counter.exe
.
For each model, in the Command Window, the build process displays a build summary.
Clean the model build area enough to trigger regeneration of the top model code at the next build.
slbuild('rtwdemo_rtwintro','CleanTopModel')
Generate code and build an executable image for
rtwdemo_mdlreftop
, which refers to model
rtwdemo_mdlrefbot
, regardless of model checksums and parameter
settings.
slbuild('rtwdemo_mdlreftop','StandaloneCoderTarget', ... 'ForceTopModelBuild',true)
model
— Specifies model for the build processIf 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
buildSpec
— Specifies the code generation action for the build process'StandaloneCoderTarget'
(default) | 'ModelReferenceSimTarget'
| 'ModelReferenceCoderTarget'
| 'ModelReferenceCoderTargetOnly'
| '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 | Build Action |
---|---|
| 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 simulation target (does not require a Simulink Coder license). |
| Builds a model reference Simulink Coder target and the corresponding model reference simulation target. |
| Builds only a model reference Simulink Coder target. |
| Cleans the model build area enough to trigger regeneration of the top model code at the next build. |
Example: 'ModelReferenceSimTarget'
Specify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
'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 any changes
detected | Rebuilds the model if the build process detects any changes. |
| If any 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'
To use this option, set buildSpec
to
'ModelReferenceSimTarget'
,
'ModelReferenceCoderTarget'
, or
'ModelReferenceCoderTargetOnly'
.
Data Types: char
| string
'ForceTopModelBuild'
— Option to force top model of model hierarchy to buildfalse
(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 image for the top
model of the model hierarchy, regardless of model checksums and
parameter settings.
Example: 'ForceTopModelBuild',true
To use this option, set buildSpec
to
'StandaloneCoderTarget'
.
Data Types: logical
'OpenBuildStatusAutomatically'
— Option to display build informationfalse
(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.
To use this option, set buildSpec
to
'StandaloneCoderTarget'
.
Data Types: logical
'IncludeModelReferenceSimulationTargets'
— Option to build model reference simulation targetsfalse
(default) | true
Option to build model reference simulation targets, specified as the
comma-separated pair consisting of
'IncludeModelReferenceSimulationTargets'
and
true
or false
.
To use this option, set buildSpec
to
'StandaloneCoderTarget'
.
Data Types: logical
slbuild
does not generate model reference simulation targets by defaultBehavior changed in R2020b
Starting in R2020b, the slbuild
function does not generate
model reference simulation targets by default. Excluding the model reference
simulation targets allows for faster code generation for model hierarchies.
You can generate both the simulation and code generation targets with the default
buildSpec
value
('StandaloneCoderTarget'
) by setting
IncludeModelReferenceSimulationTargets
to
true
.
'StandaloneRTWTarget'
, 'ModelReferenceRTWTarget'
, and
'ModelReferenceRTWTargetOnly'
arguments are not
recommendedNot recommended starting in R2019a
In R2019a, some arguments used with the slbuild
function were
updated. Legacy arguments are supported for backward compatibility.
To take advantage of the updated arguments:
Use 'StandaloneCoderTarget'
instead of
'StandaloneRTWTarget'
Use 'ModelReferenceCoderTarget'
instead of
'ModelReferenceRTWTarget'
Use 'ModelReferenceCoderTargetOnly'
instead of
'ModelReferenceRTWTargetOnly'
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.
rtwbuild
(Simulink Coder) | rtwrebuild
(Simulink Coder)