Skip to Main Content Skip to Search
Product Documentation

Generated Code Files for Targets You Build

S-Function MEX-Files

If you have a Simulink model named mainModel.mdl, which contains two Stateflow blocks named chart1 and chart2, you have a machine named mainModel that parents two charts named chart1 and chart2.

When you simulate the Stateflow chart for mainModel.mdl, you generate code for mainModel.mdl that compiles into an S-function MEX-file. MEX-file extensions are platform-specific, as described in the MATLAB software documentation. For example, on 32-bit Windows PC platforms, you generate a MEX-file for mainModel named mainModel_sfun.mexw32. On Linux® x86-64 platforms, you generate mainModel_sfun.mexa64.

S-function MEX files appear in the current MATLAB folder. You can change this location at the MATLAB command prompt with a cd command.

Folder Structure of Generated Files

Most of the code files that you generate reside in a subfolder of the current MATLAB folder. This table summarizes the default folder structure for different targets.

Target TypeModel TypeFolder Under <pwd>/slprj/_sfprj/<mainModel>
SimulationMain (nonlibrary)/_self/sfun/src
SimulationLibrary/<libModel>/sfun/src
EmbeddableMain (nonlibrary)/_self/rtw/<sys_targ>/src
EmbeddableLibrary/<libModel>/rtw/<sys_targ>/src
CustomMain (nonlibrary)/_self/<custom>/src
CustomLibrary/<libModel>/<custom>/src

These definitions apply to the table:

For embeddable targets, the integrated C code for the entire model resides in the subfolder <mainModel>_<sys_targ>_rtw of the current MATLAB folder. The executable file generated for the entire model resides in the current MATLAB folder.

Code Files for a Simulation Target

For a simulation target, you generate these files:

For library models, a static library file named <libModel>_sfun resides in the same folder as the source code. The file extension depends on the platform. On a Windows operating system, the library file is <libModel>_sfun.lib, but on a UNIX operating system, the library file is <libModel>_sfun.a.

Code Files for an Embeddable Target

For an embeddable target, you generate integrated C code for the entire model:

You also generate intermediate code files during the target building process:

Other auxiliary files can appear depending on the type of embeddable target you choose for code generation.

Code Files for a Custom Target

For a custom target, you generate these files:

Makefiles

You generate makefiles for your model that are platform and compiler-specific. On UNIX platforms, you generate a gmake-compatible makefile named <mainModel>_sfun.mku that compiles all your generated code into an executable. On PC platforms, you generate an ANSI-C compiler-specific makefile based on your C-MEX setup:

CompilerMakefileSymbol Definition File
Microsoft® Visual C++®<mainModel>_sfun.mak<mainModel>_sfun.def (required to build S-function MEX-files)
Open Watcom<mainModel>_sfun.wmkNone
lcc-win32 (default ANSI-C compiler)<mainModel>_sfun.lmkNone

  


Free Stateflow Interactive Kit

Learn how engineers use Stateflow to model state machines in their Simulink models.


Get free kit

Trials Available

Try the latest version of Stateflow.


Get trial software
 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS