Main Content

Compile Source Code for Functional Mockup Units

When you build a model that includes FMU blocks, you must compile the FMU source code by using the QNX® Neutrino® compiler qcc or q++. This compiler creates shared object SO files that you include in the FMU. This process makes sure that the FMU contains the code to run on a Simulink® Real-Time™ target computer. For more information, see Apply Functional Mockup Units by Using Simulink Real-Time.

Configure Compiler Environment Variables

The support package for the target computer includes the QNX Neutrino C/C++ compiler qcc or q++. Before using the compiler to generate the FMU file, configure the compiler environment variables.

  1. Open a Windows cmd window and change folders to the root folder for the Simulink Real-Time Target Support Package. If you have changed the default folder for MATLAB support packages, adjust this command to match your custom location. At the Windows command prompt, type:

    cd C:\ProgramData\MATLAB\SupportPackages\<release>\toolbox\slrealtime\target\supportpackage\qnx700
  2. To set the Windows environment variables that are required to use the QNX Neutrino compiler from the command line, run the batch file qnxsdp-env.bat. At the Windows command prompt, type:

  3. Ensure that the qcc compiler is ready to use. At the Windows prompt, type:

    which qcc

    The command returns:


Create the FMU File

The FMU file contains a hierarchy of files and folders. A set of these is provided in this example. The example shows how to create the shared object file for a single source file that is linked in the real-time application that runs on the target computer.

To view the files for this example, in the MATLAB Command Window, type:

cd(fullfile(matlabroot, 'toolbox', 'slrealtime', ...
'examples', 'slrt_ex_fmu_work'))

To open the model for this example, in the MATLAB Command Window, type:

open_system(fullfile(matlabroot, 'toolbox', 'slrealtime', ...
'examples', 'slrt_ex_vanderpol'))
  1. The example FMU file vanDerPol_slrt.fmu contains this set of folders:

  2. The example has FMU source files in the sources folder. This example uses files: fmuTemplate.c, fmuTemplate.h, vanDerPol.c

  3. The example has a dynamically linked library file from the source files that was created by using a Window-based compiler. This file is in the win64 folder. This example uses file: vanDerPol.dll

  4. To compile the sources in the example by using qcc, copy the files for the FMU from folder matlab/slrealtime/examples/slrt_ex_fmu_work to folder C:\work\my_fmu_work.

  5. In a Windows cmd window, change the current folder to be the location of your source files. At the Windows command prompt, type:

    cd C:\work\my_fmu_work\sources
  6. To generate the QNX Neutrino shared object SO file, the example compiles the sources by using the -Vgcc_ntox86_64 flag. At the Windows command prompt, type:

    qcc -Vgcc_ntox86_64 -shared -o ../binaries/slrt_x64/ -fPIC -DFMI_COSIMULATION -IC:/PROGRA~1/MATLAB/R2020b_bash/rtw/c/src/rapid/fmu vanDerPol.c


    The QNX Neutrino compiler does not support Windows long file names (for example, paths with space characters) for the library search switch -I. To work around this limitation, you can install MATLAB® in a path without spaces (for example, C:\MATLAB) or you can use the DOS 8.3 path in the compiler command. To get the 8.3 folder names, you can use the dir /x command in a Windows cmd window.

  7. To generate the functional mockup unit FMU file that contains the QNX Neutrino shared object file, the example archives the folders and files. Use the FMU extension for the archive file. At the Windows command prompt, type:

    cd ..
    zip -r vanDerPol.fmu *

Implement the FMU Block in Model

To implement the vanDerPol block in the Simulink model by using the FMU, specify the FMU name for the block. Open the model slrt_ex_vanderpol, double-click the FMU block vanDerPol, and select the vanDerPol.fmu file for the FMU name block parameter.

Build the model, load the real-time application on the target computer, and run the real-time application.

See Also

Related Topics

External Websites