Main Content

rtwbuild

(Not recommended) Build generated code from a model

rtwbuild is not recommended. Use slbuild instead.

Description

rtwbuild(model) generates code from model based on current model configuration parameter settings. If model is not already loaded into the MATLAB® environment, rtwbuild loads it before generating code.

If you clear the Generate code only model configuration parameter, the function generates code and builds an executable image.

To reduce code generation time, when rebuilding a model, rtwbuild provides incremental model build. The code generator rebuilds a model or submodels only when they have changed since the most recent model build. To force a top-model build, see the 'ForceTopModelBuild' argument.

rtwbuild(model,Name,Value) uses additional options specified by one or more Name,Value pair arguments.

rtwbuild(subsystem) generates code from subsystem based on current model configuration parameter settings. Before initiating the build, open (or load) the parent model.

If you clear the Generate code only model configuration parameter, the function generates code and builds an executable image.

rtwbuild(subsystem,'Mode','ExportFunctionCalls') generates code from subsystem that includes function calls that you can export to external application code if you have Embedded Coder®.

blockHandle = rtwbuild(subsystem,'Mode','ExportFunctionCalls') returns the handle to a SIL block created for code generated from the specified subsystem if the Create block configuration parameter is set to SIL and if you have Embedded Coder. You can then use the SIL block for numerical equivalence testing.

Input Arguments

collapse all

Model for which to generate code or build an executable image, specified as an object or a character vector representing the model name.

Example: 'rtwdemo_exporting_functions'

Subsystem for which to generate code or build an executable image, specified as a character vector representing the subsystem name or the full block path.

Example: 'rtwdemo_exporting_functions/rtwdemo_subsystem'

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: rtwbuild('TopModelCode','ForceTopModelBuild',true)

Force regeneration of top model code, specified as true or false.

ActionSpecify
Force the code generator to regenerate code for the top model of a system that includes referenced models true
Specify that the code generator determine whether to regenerate top model code based on model and model parameter changes false

Consider forcing regeneration of code for a top model if you change items associated with external or custom code, such as code for a custom target. For example, set ForceTopModelBuild to true if you change:

  • TLC code

  • S-function source code, including rtwmakecfg.m files

  • Integrated custom code

Alternatively, you can force regeneration of top model code by deleting folders in the Code generation folder, such as slprj or the generated model code folder.

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.

ActionSpecify

Generate code only.

true

Generate code and build executable file.

false
  • 'ExportFunctionCalls' –– If you have Embedded Coder, generates code from subsystem that includes function calls that you can export to external application code.

  • 'Normal' –– Does not export function calls.

Name the exported initialization function for specified subsystem.

Example: rtwbuild(subsystem,'Mode','ExportFunctionCalls','ExportFunctionInitializeFunctionName', fcnname)

Display build information in the Build Status window, specified as true or false. For more information about using the Build Status window, see Monitor Parallel Building of Referenced Models.

The Build Status window supports parallel builds of referenced model hierarchies. Do not use the Build Status window for serial builds.

ActionSpecify
Display build information in the Build Status windowtrue
No actionfalse

Specify whether to generate obfuscated C code, specified as true or false.

ActionSpecify
Generate obfuscated C code that you can share with third parties with reduced likelihood of compromising intellectual property.true
No action.false

Option to build model reference simulation targets, specified as the comma-separated pair consisting of 'IncludeModelReferenceSimulationTargets' and true or false.

Data Types: logical

Output Arguments

collapse all

Handle to SIL block created for generated subsystem code. Returned only if both of the following conditions apply:

  • You are licensed to use Embedded Coder software.

  • Create block model configuration parameter is set to SIL.

Tips

You can initiate code generation and the build process by:

  • Pressing Ctrl+B.

  • Selecting Code > C/C++ Code > Build Model.

  • Invoking the slbuild command from the MATLAB command line.

Extended Capabilities

Version History

Introduced in R2009a

expand all