How can I use the Real-Time Workshop generated code in a cross-platform development environment for R12 and R12.1?

6 views (last 30 days)
How can I use the Real-Time Workshop generated code in a cross-platform development environment for R12 and R12.1?
For example if I generate C code via RTW on a PC, then want to take it onto a Unix machine, compile it with a Unix native C compiler, and create an executable for Unix (e.g. Solaris). Is this possible?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
Here is the recommended procedure for using RTW in a cross-platform development environment for R12 and R12.1. Steps 1 and 2 are configuration steps which you only need to do once.
STEP 1: Create the requisite MATLAB tree on the UNIX machine necessary to compile RTW programs. You need to copy the following directories from the PC MATLAB installation onto your UNIX machine:
simulink/include
extern/include
rtw/c/grt
rtw/c/libsrc
rtw/c/src
rtw/c/tools
For the purposes of this example. We assume you installed these files in a directory such as: '/home/rtwuser/cross'.
NOTE: Your make utility and compiler may be sensitive to DOS/UNIX end-of-line character differences. We recommend you run a dos2unix file conversion utility to ensure your files have a UNIX end-of-line.
STEP 2: Create a cross-platform template makefile on your PC.
'cd' to directory matlabroot/rtw/c/grt in your PC MATLAB installation. Copy the file grt_unix.tmf to grt_cross.tmf. Make the following changes to grt_cross.tmf:
Change two token lines:
From:
MATLAB_ROOT = |>MATLAB_ROOT<|
To:
MATLAB_ROOT = /home/rtwuser/cross
and From:
COMPUTER = |>COMPUTER<|
To:
COMPUTER = SOL2
NOTE: This 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.
Next, on the platform that you will be cross-developing on, type the command COMPUTER in MATLAB. Take the result of that command and use that value for the COMPUTER in the token line. Type 'help computer' in your PC MATLAB session for a list of legal values.
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
STEP 3: Generate code and makefile on PC
Bring up your Simulink model in MATLAB. On the RTW Page change the template makefile to be 'grt_cross.tmf'. Select the 'Build' button.
You should see RTW generate code and a makefile, but not build the executable. 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, and model_common.h
You may again need to run a dos2unix utility against the generated code so it will conform to UNIX end-of-line characters.
STEP 4: Building on UNIX Platform
'cd' to the UNIX working directory where you copied the RTW model code (copied in STEP 3)
To build the RTW program type following at your UNIX prompt:
make -f model.mk
NOTE: Errors you might see:
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 3.
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 STEP1. 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!