Products & Services Solutions Academia Support User Community Company

Learn more about Real-Time Workshop   

Choosing and Configuring a Compiler

Compilers and the Build Process

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 Product and ANSI[1] C/C++ Compliance

The Real-Time Workshop software generates code that is compliant with the following standards:

LanguageSupported Standard
CISO/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:

Additionally, the Real-Time Workshop software can incorporate code from

Support for C and C++ Code Generation

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:

For a demo, enter sfcndemo_cppcount in the MATLAB Command Window. For a Stateflow example, enter sf_cpp.

C++ Target Language Limitations

Support for International (Non-US-ASCII) Characters

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:

Additional Support with Real-Time Workshop Embedded Coder

Users of Real-Time Workshop Embedded Coder have additional international character support:

Character Set Limitation

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.

C++ Target Language Considerations

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.

Choosing and Configuring Your Compiler on a Microsoft Windows Platform

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.

Choosing and Configuring Your Compiler on The Open Group UNIX Platforms

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.

Including S-Function Source Code

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.

  


Related Products & Applications

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