slbuild
Generate and compile standalone or model reference code from model
Syntax
Description
slbuild( builds the specified
model. Depending on the configuration parameter settings, the build process can
generate code only or generate and compile code to create a binary file. If the
model is not loaded, mdl)slbuild loads the model before
starting the build process.
slbuild(
generates code, and depending on configuration parameter settings, creates a
binary file from the model as specified by one or more name-value
arguments.mdl,Name=Value)
generates subsystem code and creates a binary 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 creates a binary file as specified by one or more
name-value arguments.blockHandle = slbuild(subsystem,Name=Value)
Examples
Generate C code for model CounterModel.
openExample("CounterModel") slbuild("CounterModel")
Calling the slbuild function with only one argument
performs the same operation as calling the slbuild
function with the second argument set to
"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 |
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. For each model, the build process displays a build summary.
slbuild(["CounterModel","ParallelBuildA1"])
### Searching for referenced models in model 'CounterModel'. ### Total of 1 models to build. ### 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 1m 54.29s 1 of 1 models built (0 models already up to date) Build duration: 0h 2m 1.2556s ### Searching for referenced models in model 'ParallelBuildA1'. ### Total of 4 models to build. 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 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 2m 22.982s ParallelBuildB2 Target (ParallelBuildB2.c) did not exist. Code generated and compiled. 0h 2m 23.304s ParallelBuildB3 Target (ParallelBuildB3.c) did not exist. Code generated and compiled. 0h 2m 23.398s Top model targets: Model Build Reason Status Build Duration ================================================================================================================== ParallelBuildA1 Information cache folder or artifacts were missing. Code generated and compiled. 0h 0m 44.222s 4 of 4 models built (0 models already up to date) Build duration: 0h 9m 21.925s ### Cleaning up parallel workers.
In the current folder, the build process creates standalone executable
files, CounterModel.exe and
ParallelBuildA1.exe.
Generate code and create an executable file for the model
TopModelCode, which references to model
ReferenceModelCode, regardless of model checksums and
parameter settings.
openExample("simulinkcoder/FilePackagingModelsCodeAndDataExample",... supportingFile="TopModelCode"); slbuild("TopModelCode","StandaloneCoderTarget",... ForceTopModelBuild=true)
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.
To export function calls to external application code, create 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.
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
If you specify the model name as a handle, string, or character vector, the build process creates a binary file or model reference target.
If you specify multiple models through a string array or cell array, the
build process applies buildSpec to each model in the
array.
Example: slbuild("CounterModel")
Name of subsystem from which you want to generate code or create a binary file, specified as a handle, string, or character vector representing the subsystem name or the full block path.
You can specify multiple subsystems through a string array or cell array.
Example: slbuild("SimulinkFunctions/util")
buildSpec directs the code generator to perform the
selected build action for the model.
The build process requires a Simulink® Coder™ license only if you create a model reference Simulink Coder target, not if you create only a model reference simulation target.
The buildSpec argument must be one of the
following.
buildSpec Value | Build Action | Notes |
|---|---|---|
| Depending on the model configuration parameter settings, the build process can generate code only or generate and compile code to create a binary file. It also creates model reference coder targets for the referenced models. If the specified model is
not loaded, |
|
| Creates a model reference Simulink Coder target. |
|
| Creates 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 Subcomponent from the Deployment Type menu. |
Example: slbuild("CounterModel","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: slbuild("CounterModel",BuildOutputType="StaticLibrary")
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 source code only or source code and a binary file from the top model. The output type of the build process depends on the model configuration parameter settings. For example:
|
| In the code generation folder, create a standalone
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: slbuild("CounterModel",BuildOutputType="StaticLibrary")
Dependencies
To use this option, set buildSpec to
"StandaloneCoderTarget".
Option to force the build of the top model of the model hierarchy,
specified as true or false.
Setting the value to true directs the code
generator to generate code and create an executable file for the top
model of the model hierarchy, regardless of model checksums and
parameter settings.
Example: slbuild("CounterModel",ForceTopModelBuild=true)
Dependencies
To use this option, set buildSpec to
"StandaloneCoderTarget".
Data Types: logical
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 create executable file.
Dependencies
To use this option, set buildSpec to
"StandaloneCoderTarget" or
"ModelReferenceCoderTarget".
"ExportFunctionCalls"— If you have Embedded Coder, generates code fromsubsystemthat includes function calls that you can export to external application code."Normal"— Does not export function calls.
Name the exported function for the specified subsystem.
Example: slbuild(subsystem,Mode="ExportFunctionCalls",ExportFunctionFileName=fcnname)
Name the exported initialization function for specified subsystem.
Example: slbuild(subsystem,Mode=ExportFunctionCalls",ExportFunctionInitializeFunctionName=fcnname)
Option to display the build information, specified as
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
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
Block handle to an autogenerated S-Function wrapper block or Model block.
Extended Capabilities
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 R2006aThe UpdateThisModelReferenceTarget name-value argument of the
slbuild function will be removed in a future release. This
argument lets you build the model reference simulation or coder target for only the
specified model and not its referenced models.
To avoid rebuilding model reference targets for referenced models, convert the referenced models to protected models instead. For more information, see Protect Models to Conceal Contents (Simulink Coder).
To control what model reference targets build during simulation or code generation, use the strategies in this table instead.
UpdateThisModelReferenceTarget Value | Recommended Replacement |
|---|---|
"IfOutOfDate" or
"IfOutOfDateOrStructuralChange" | To rebuild model reference targets conditionally, set the
|
"Force" | To rebuild model reference targets unconditionally, remove the related Simulink cache files and model reference targets. For more information, see Manage Simulation Targets for Referenced Models and Manage Build Process Folders (Simulink Coder). |
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.
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.
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'.
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) | coder.buildstatus.open (Simulink Coder) | coder.buildstatus.close (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)