How can I use the generated code from Real-Time Workshop 5.0 (R13) or 5.1 (R13SP1) in a cross-platform development environment?

3 views (last 30 days)
I would like to use Real-Time Workshop to generate C-code on a PC. I would like to bring it to the UNIX platform, compile it with a UNIX native C compiler, and create an executable for UNIX (e.g. Solaris).

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 17 Aug 2009
This change has been incorporated into the documentation in Release 14 Service Pack 3 (R14SP3). For previous releases, read below for any additional information:
Here is the recommended procedure for using Real-Time Workshop 5.0 (R13) or 5.1 (R13SP1) in a cross-platform development environment. These steps describe the process for the GRT target, but can be adapted to use the ERT target as well.
Note that if you are using Real-Time Workshop 6.1 (R14SP1), see the Related Solution listed at the bottom of the page.
Steps 1 and 2 are configuration steps which you only need to do once.
1. Create the requisite MATLAB tree on the UNIX machine with the source files necessary to compile RTW programs. Copy the following directories from the PC MATLAB installation onto your UNIX machine. (Note: These paths include the source code necessary for Simulink library blocks only.)
simulink/include
extern/include
rtw/c/grt
rtw/c/libsrc
rtw/c/src
rtw/c/tools
For the purposes of this example, we will assume you installed these files in a directory called:
/home/rtwuser/cross
NOTE: Your make utility and compiler may be sensitive to DOS/UNIX end-of-line character differences. We recommend you also run a dos2unix file conversion utility to ensure your files have UNIX end-of-line characters.
2. Create a cross-platform template makefile on your PC. On the PC, browse to the directory
$MATLABROOT\rtw\c\grt
(where $MATLABROOT = the MATLAB root directory on your machine)
Make a copy of the file grt_unix.tmf and name it grt_cross.tmf.
3. On the platform that you will be cross-developing on, run the COMPUTER function in MATLAB.
computer
Take the result of that command and use that value from COMPUTER in the token line. You can also type
help computer
in your PC MATLAB session for a list of legal values. For the purposes of this example, we will assume the cross-development platform is 'SOL2' (Solaris).
4. Open grt_cross.tmf in the MATLAB editor or a text editor so that you can make some changes.
5. Change token line in grt_cross.tmf.
From:
MATLAB_ROOT = |>MATLAB_ROOT<|
To:
MATLAB_ROOT = /home/rtwuser/cross
6. Change token line in grt_cross.tmf:
From:
COMPUTER = |>COMPUTER<|
To:
COMPUTER = SOL2
NOTE: This is assuming the cross-development platform is 'SOL2' (Solaris). This change will hard-code the template makefile to use /home/rtwuser/cross as your MATLAB tree and also hard-codes the template makefile to build on a Solaris machine.
7. Change the following lines to hard-code the makefile to build rtwlib.a.
From:
ifeq ($(OPT_OPTS),$(DEFAULT_OPT_OPTS))
RTWLIB = $(MATLAB_ROOT)/rtw/c/lib/$(ARCH)/rtwlib_std.a
else
RTWLIB = rtwlib.a
endif
To:
#ifeq ($(OPT_OPTS),$(DEFAULT_OPT_OPTS))
#RTWLIB = $(MATLAB_ROOT)/rtw/c/lib/$(ARCH)/rtwlib_std.a
#else
RTWLIB = rtwlib.a
#endif
8. Change the following lines of code under Additional Libraries:
From:
LIBS =
|>START_PRECOMP_LIBRARIES<|
ifeq ($(OPT_OPTS),$(DEFAULT_OPT_OPTS))
LIBS += |>EXPAND_LIBRARY_LOCATION<|/|>EXPAND_LIBRARY_NAME<|_std.a
else
LIBS += |>EXPAND_LIBRARY_NAME<|.a
endif
|>END_PRECOMP_LIBRARIES<| |>START_EXPAND_LIBRARIES<|
LIBS += |>EXPAND_LIBRARY_NAME<|.a |>END_EXPAND_LIBRARIES<|
LIBS += $(S_FUNCTIONS_LIB) $(INSTRUMENT_LIBS)
To:
LIBS =
|>START_PRECOMP_LIBRARIES<|
LIBS += |>EXPAND_LIBRARY_NAME<|.a
|>END_PRECOMP_LIBRARIES<| |>START_EXPAND_LIBRARIES<|
LIBS += |>EXPAND_LIBRARY_NAME<|.a |>END_EXPAND_LIBRARIES<|
LIBS += $(S_FUNCTIONS_LIB) $(INSTRUMENT_LIBS)
NOTE: If you are using the ERT target, there will be a few additional lines of code in the section to be removed.
9. On the PC, open your Simulink model and open the Simulation Parameters, Real-Time Workshop tab. Change the template makefile to be 'grt_cross.tmf'.
10. Click the 'Build' button to generate code from your model. You should see RTW generate code and a makefile, but not build the executable.
11. Copy the files from the build directory on your PC to your UNIX working directory:
rtw_proj.tmw
model.h
model_prm.h
model_export.h
model.c
model.mk
model_reg.h
model_common.h
NOTE: Your make of utility and compiler may be sensitive to DOS/UNIX end-of-line character differences. We recommend you also run a dos2unix file conversion utility to ensure your files have UNIX end-of-line characters.
12. In UNIX, browse to the working directory where you copied the RTW model code from step 11.
13. Type the following at your UNIX prompt to build the model:
make -f model.mk
NOTE: You may receive one of the following errors if you did not run a dos2unix utility:
ERROR 1:
make -f vdp.mk
: No such file or directory
vdp.mk:92: *** commands commence before first target. Stop.
Remedy: run dos2unix utility to conform to UNIX end-of-line character on the files you copied in step 11.
ERROR 2:
make -f vdp.mk
cc -c -o
vdp.o -O -DMODEL=vdp -DRT -DNUMST=2 -DTID01EQ=1 -DNCSTATES=2 -DUNIX -DMT=
0 -I. -I/home/rtwuser/cross/simulink/include -I/home/rtwuser/cross/extern/in
clude -I/home/rtwuser/cross/rtw/c/src -I/home/rtwuser/cross/rtw/c/libsrc
vdp.c
"/home/rtwuser/cross/simulink/include/simstruc.h", line 47: warning: invalid
white space character in directive
"/home/rtwuser/cross/simulink/include/simstruc.h", line 48: warning: invalid white
Remedy: This can occur if you did not follow the instructions at the end of step 1. You need to run a dos2unix utility to conform to UNIX end-of-line characters on the files you copied in step 1.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!