Target Language Compiler    

Generate Code Without a Wrapper

Before creating a wrapper, generate code that uses the Simulink generic API.

  1. Build a stand-alone model (the file will be called externalcode.exe in Windows and externalcode in UNIX environments). Click Tools -> Real-Time Workshop -> Build Model, or type Ctrl+B. Simulink will report the results, as follows:



  • ### Starting Real-Time Workshop build procedure for model: externalcode
    ### Generating code into build directory: .\externalcode_grt_rtw
    ### Invoking Target Language Compiler on externalcode.rtw
    tlc -r .\externalcode_grt_rtw\externalcode.rtw  
    'D:\MATLAB6p1\rtw\c\grt\grt.tlc' -O.\externalcode_grt_rtw  
    '-ID:\MATLAB6p1\rtw\c\grt' '-ID:\MATLAB6p1\rtw\c\tlc'  
    -aEnforceIntegerDowncast=1 -aExtMode=0 -aFoldNonRolledExpr=1 
    -aForceParamTrailComments=0 -aGenerateComments=1 
    -aIgnoreCustomStorageClasses=1 -aIncHierarchyInIds=0 
    -aInlineInvariantSignals=1 -aInlineParameters=0 -aLocalBlockOutputs=1 
    -aLogVarNameModifier="rt_" -aRTWVerbose=1 -aRollThreshold=5 
    -aShowEliminatedStatements=1 -aReleaseVersion=12.1 -p10000
    ### Loading TMW TLC function libraries
    ..
    ### Initial pass through model to cache user defined code
    ### Caching model source code
    .
    ### Creating (RealTime) source file externalcode.c
    .
    ### Creating model header file externalcode.h
    ### Creating model header file externalcode_export.h
    ### Creating parameter file externalcode_prm.h
    ### Creating registration file externalcode_reg.h
    ### TLC code generation complete.
    

  • ### Creating project marker file: rtw_proj.tmw
    ### Creating externalcode.mk from D:\MATLAB6p1\rtw\c\grt\grt_lcc.tmf
    ### Building externalcode: .\externalcode.bat
     
    D:\Work\wrapper\externalcode_grt_rtw>set MATLAB=D:\MATLAB6p1  
     
    D:\Work\wrapper\externalcode_grt_rtw>"D:\MATLAB6p1\rtw\bin\win32\gmake" -f 
    externalcode.mk   
    D:\MATLAB6p1\sys\lcc\bin\lcc -c -Foexternalcode.obj     -DMODEL=externalcode 
    -DRT -DNUMST=2 -DTID01EQ=1 -DNCSTATES=0 -DMT=0 -DHAVESTDIO -I. -I.. 
    -ID:\MATLAB6p1\simulink\include -ID:\MATLAB6p1\extern\include 
    -ID:\MATLAB6p1\rtw\c\src -ID:\MATLAB6p1\rtw\c\libsrc  
    -ID:\MATLAB6p1\sys\lcc\include  -noregistrylookup externalcode.c 
    Warning:  externalcode.c: 41  Statement has no effect 
    0 errors, 1 warnings 
    

  • D:\MATLAB6p1\sys\lcc\bin\lcc -c -Fogrt_main.obj     -DMODEL=externalcode -DRT 
    -DNUMST=2 -DTID01EQ=1 -DNCSTATES=0 -DMT=0 -DHAVESTDIO -I. -I.. 
    -ID:\MATLAB6p1\simulink\include -ID:\MATLAB6p1\extern\include 
    -ID:\MATLAB6p1\rtw\c\src -ID:\MATLAB6p1\rtw\c\libsrc  
    -ID:\MATLAB6p1\sys\lcc\include -noregistrylookup 
    D:\MATLAB6p1/rtw/c/grt/grt_main.c 
    D:\MATLAB6p1\sys\lcc\bin\lcc -c -Fort_sim.obj     -DMODEL=externalcode -DRT 
    -DNUMST=2 -DTID01EQ=1 -DNCSTATES=0 -DMT=0 -DHAVESTDIO -I. -I.. 
    -ID:\MATLAB6p1\simulink\include -ID:\MATLAB6p1\extern\include 
    -ID:\MATLAB6p1\rtw\c\src -ID:\MATLAB6p1\rtw\c\libsrc  
    -ID:\MATLAB6p1\sys\lcc\include  -noregistrylookup 
    D:\MATLAB6p1/rtw/c/src/rt_sim.c 
    D:\MATLAB6p1\sys\lcc\bin\lcc -c -Fortwlog.obj     -DMODEL=externalcode -DRT 
    -DNUMST=2 -DTID01EQ=1 -DNCSTATES=0 -DMT=0 -DHAVESTDIO -I. -I.. 
    -ID:\MATLAB6p1\simulink\include -ID:\MATLAB6p1\extern\include 
    -ID:\MATLAB6p1\rtw\c\src -ID:\MATLAB6p1\rtw\c\libsrc  
    -ID:\MATLAB6p1\sys\lcc\include  -noregistrylookup 
    D:\MATLAB6p1/rtw/c/src/rtwlog.c 
    D:\MATLAB6p1\sys\lcc\bin\lcc -c -Fort_nonfinite.obj     -DMODEL=externalcode 
    -DRT -DNUMST=2 -DTID01EQ=1 -DNCSTATES=0 -DMT=0 -DHAVESTDIO -I. -I.. 
    -ID:\MATLAB6p1\simulink\include -ID:\MATLAB6p1\extern\include 
    -ID:\MATLAB6p1\rtw\c\src -ID:\MATLAB6p1\rtw\c\libsrc  
    -ID:\MATLAB6p1\sys\lcc\include  -noregistrylookup 
    D:\MATLAB6p1/rtw/c/src/rt_nonfinite.c 
    

  • D:\MATLAB6p1\sys\lcc\bin\lcclnk -s -LD:\MATLAB6p1\sys\lcc\lib -o
    ../externalcode.exe externalcode.obj  grt_main.obj rt_sim.obj rtwlog.obj 
    rt_nonfinite.obj      D:\MATLAB6p1\rtw\c\lib\win32\rtwlib_lcc.lib    
    ### Created executable: externalcode.exe  
    ### Successful completion of Real-Time Workshop build procedure for model: 
    externalcode
    
  1. Real-Time Workshop creates the stand-alone program, externalcode.exe, in your working directory and places the source and object files in your build directory.

  1. Run the stand-alone to see that it behaves the same as the Simulink version. There should be no differences:
  2. Inspect the mdloutputs() function of the code in wrapsfcn.c to see how the external function is called:
  1. Notice this line in wrapsfcn.c:

    This pulls in the external function. That function consists entirely of

Generally, functions to be wrapped are either included in the wrapper, as above, or (when object modules are being wrapped) are resolved at link time.


  Getting Started Generate Code Using a Wrapper