| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Real-Time Workshop |
| Contents | Index |
| Learn more about Real-Time Workshop |
The Real-Time Workshop build process depends upon the correct installation of one or more supported compilers. Compiler, in this context, refers to a development environment containing a linker and make utility, in addition to a high-level language compiler. For details on supported compiler versions, see
http://www.mathworks.com/support/compilers/current_release
Most Real-Time Workshop targets create an executable that runs on your workstation. When creating the executable, the Real-Time Workshop build process must be able to access an appropriate compiler. The build process can automatically find a compiler to use based on your default MEX compiler.
The build process also requires the selection of a template makefile. The template makefile determines which compiler runs, during the make phase of the build, to compile the generated code.
To determine which template makefiles are appropriate for your compiler and target, see Targets Available from the System Target File Browser.
For both Real-Time Workshop generated files and user-supplied files, the file extension, .c or .cpp, determines whether a C or a C++ compiler will be used in the Real-Time Workshop build process. If the file extension is .c, a C compiler will be used to compile the file, and the symbols will use the C linkage convention. If the file extension is .cpp, a C++ compiler will be used to compile the file, and the symbols by default will use the C++ linkage specification.
The Real-Time Workshop software generates code that is compliant with the following standards:
| Language | Supported Standard |
|---|---|
| C | ISO/IEC 9899:1990, also known as C89/C90 |
| C++ | ISO/IEC 14882:2003 |
Code generated by the Real-Time Workshop software from the following sources is ANSI C/C++ compliant:
Simulink built-in block algorithmic code
Real-Time Workshop and Real-Time Workshop Embedded Coder system level code (task ID [TID] checks, management, functions, and so on)
Code from other blocksets, including the Simulink Fixed Point product, the Communications Blockset™ product, and so on
Code from other code generators, such as the Stateflow® Coder™ product and Embedded MATLAB functions
Additionally, the Real-Time Workshop software can incorporate code from
Embedded targets (for example, startup code, device driver blocks)
User-written S-functions or TLC files
Note Coding standards for these two sources are beyond the control of the Real-Time Workshop software, and can be a source for compliance problems, such as code that uses C99 features not supported in the ANSI C, C89/C90 subset. |
Real-Time Workshop supports C and C++ code generation. The primary motivation for C++ support is to facilitate integration of generated code with legacy or custom user code written in C++. Consider the following as you choose a language for your generated code:
Whether you need to configure Real-Time Workshop to use a specific compiler. This is required to generate C++ code on Windows. See Choosing and Configuring a Compiler.
The language configuration setting for the model. See Selecting a Target Programming Language.
Whether you need to integrate legacy or custom code with generated code. For a summary of integration options, see Integration Options.
Whether you need to integrate C and C++ code. If so, see About External Code Integration.
Note You can mix C and C++ code when integrating Real-Time Workshop generated code with custom code. However, you must be aware of the differences between C and default C++ linkage conventions, and add the extern "C"' linkage specifier wherever it is appropriate. For the details of the differing linkage conventions and how to apply extern "C", refer to a C++ programming language reference book. |
For a demo, enter sfcndemo_cppcount in the MATLAB Command Window. For a Stateflow example, enter sf_cpp.
Real-Time Workshop does not support C++ code generation for the following:
| SimDriveline™ |
| SimMechanics™ |
| SimPowerSystems™ |
| Target Support Package |
| Target Support Package |
| Target Support Package |
| Target Support Package |
| xPC Target |
The following Real-Time Workshop Embedded Coder dialog box fields currently do not accept the .cpp extension. However, a .cpp file will be generated if you specify a filename without an extension in these fields, with C++ selected as the target language for your generated code.
Data definition filename field on the Data Placement pane of the Configuration Parameters dialog box
Definition file field for an mpt data object in the Model Explorer
These restrictions on specifying .cpp will be removed in a future release.
Real-Time Workshop does not include non-US-ASCII characters in compilable portions of source code. However, Simulink, Stateflow, Real-Time Workshop, and Real-Time Workshop Embedded Coder do support non-US-ASCII characters in certain ways. When non-US-ASCII characters are encountered during code generation, they either become comments in the generated code or do not propagate into the generated source files. Sources of non-US-ASCII characters are described below:
Simulink Block Names: The name of Simulink blocks are permitted to use non-US-ASCII character sets. The block name can be output in a comment above the generated code for that block when the Simulink block / Stateflow object comments check box is selected. If Real-Time Workshop also uses the block name in the generated code as an identifier, the identifier's name will be changed to ensure only US-ASCII characters are present.
One exception to using non-US-ASCII characters in block names is for nonvirtual subsystems configured to use the subsystem name as either the function name or the filename. In this case, only US-ASCII characters can be used to name the subsystem.
User comments on Stateflow diagrams: These comments can contain non-US-ASCII characters. They are written to the generated code when the Include comments check box is selected.
Custom TLC files (.tlc): User-created Target Language Compiler files can have non-US-ASCII characters inside both TLC comments and in any code comments which are output. The Target Language Compiler does not support non-US-ASCII characters in TLC variable or function names.
Users of Real-Time Workshop Embedded Coder have additional international character support:
Simulink Block Description: Real-Time Workshop Embedded Coder propagates block descriptions entered from Simulink Block Parameter dialog boxes into the generated code as comments when the Simulink block descriptions check box on the Real-Time Workshop/Comments pane of the Configuration Parameters dialog box is selected. Non-US-ASCII characters are supported for these descriptions.
Real-Time Workshop Embedded Coder code template file: Code Generation Template (.cgt) files provide customization capability for the generated code. Any output lines in the .cgt file which are C or C++ comments can contain non-US-ASCII characters, for example the file banner and file trailer sections; these comments are propagated to the generated code. However, although TLC comments in .cgt files can contain non-US-ASCII characters, these TLC comments are not propagated to the generated code.
Stateflow object descriptions: Stateflow object descriptions can contain non-US-ASCII characters. The description will appear as a comment above the generated code for that chart when the Stateflow object descriptions check box is selected.
Simulink Parameter Object Description: Simulink Parameter Object descriptions can contain non-US-ASCII characters. The description will appear as a comment above the generated code when the Simulink data object descriptions check box is selected.
MPT Signal Object Description: MPT object descriptions can contain non-US-ASCII characters. The description will appear as a comment above the generated code when the Simulink data object descriptions check box is selected.
You can encounter problems with models containing characters of a specific character set, such as Shift JIS, on a host system for which that character set is not configured as the default.
When models containing characters of a given character set are used on a host system that is not configured with that character set as the default, Simulink can incorrectly interpret characters during model loading and saving. This can lead to corrupted characters being displayed in the model and possibly the model failing to load. It can also lead to corrupted characters in the model file (.mdl) if you save it.
This limitation does not exist when the characters used in the model are in the default character set for the host system. For example, you can use Shift JIS characters with no issues if the host system is configured to use Japanese Windows.
Additionally, during code generation, the Target Language Compiler can have similar problems reading characters from either the model.rtw or user written .tlc files. This can result in corrupt characters in generated source file comments or a Target Language Compiler error.
For an example of international character set support for code generation, run the demo model rtwdemo_international. This demo model is set up to work around the character limitations described above. If you run this demo from a non-Japanese MATLAB host machine, you must set up an international character set for Simulink. For example, type
bdclose all; set_param(0, 'CharacterEncoding', 'Shift_JIS') rtwdemo_international
Other uses of non-US-ASCII characters in models or in files used during the build process are not supported; you should not depend on any incidental functionality that may exist.
For additional information, see the description of slCharacterEncoding in Model Construction in the Simulink documentation.
To use the C++ target language support, you might need to configure the Real-Time Workshop software to use the appropriate compiler. For example, on a Microsoft Windows platform the default compiler is the Lcc C compiler shipped with the MATLAB product, which does not support C++. If you do not configure the Real-Time Workshop software to use a C++ compiler before you specify C++ for code generation, the following build error message appears:
The specified Real-Time Workshop target is configured to generate C++, but the C-only compiler, LCC, is the default compiler. To specify a C++ compiler, enter 'mex -setup' at the command prompt. To generate C code, click (Open) to open the Configuration Parameters dialog and set the target language to C.
On Windows platforms, you can use the Lcc C compiler shipped with the MATLAB product, or you can install and use one of the supported Windows compilers.
The Real-Time Workshop code generator will choose a compiler based on the template makefile (TMF) name specified on the Real-Time Workshop pane of the Configuration Parameters dialog box. The simplest approach is to let the code generator pick a compiler based on your default compiler, as set up using the mex -setup function. When you use this approach, you do not need to define compiler-specific environment variables, and the Real-Time Workshop code generator determines the location of the compiler using information from the mexopts.bat file located in the preferences directory (use the prefdir command to verify this location).
To use this approach, the TMF filename specified must be an M-file that returns default compiler information by using the mexopts.bat file. Most targets provided by the Real-Time Workshop product use this approach, as when grt_default_tmf or ert_default_tmf is specified as the TMF name.
Alternatively, the name provided for the TMF can be a compiler-specific template makefile, for example grt_vc.tmf, which designates the Microsoft Visual C++ compiler. When you provide a compiler-specific TMF filename, the Real-Time Workshop code generator uses the default mexopts.bat information to locate the compiler if mex has been set up for the same compiler as the specified TMF. If mex is not set up with a default compiler, or if it does not match the compiler specified by the TMF, then an environment variable must exist for the compiler specified by the TMF. The environment variable required depends on the compiler.
On a UNIX platform, the Real-Time Workshop build process uses the default compiler. For all operating systems except the Sun™ operating system, cc is the default compiler. On a Sun operating system, the default is gcc.
You should choose the UNIX template makefile that is appropriate to your target. For example, grt_unix.tmf is the correct template makefile to build a generic real-time program on a UNIX platform.
When the Real-Time Workshop code generator builds models with S-functions, source code for the S-functions can be either in the current directory or in the same directory as their MEX-file. The code generator adds an include path to the generated makefiles whenever it finds a file named sfncname.h in the same directory that the S-function MEX-file is in. This directory must be on the MATLAB path.
Similarly, the Real-Time Workshop code generator adds a rule for the directory when it finds a file sfncname.c (or .cpp) in the same directory as the S-function MEX-file is in.
[1] ANSI is a registered trademark of the American National Standards Institute, Inc.
![]() | Building Executables | Configuring the Build Process | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |