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.
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.
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:
C:
cd C:\ProgramData\MATLAB\SupportPackages\<release>\toolbox\slrealtime\target\supportpackage\qnx700
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:
qnxsdp-env.bat
Ensure that the qcc
compiler is ready to use. At the
Windows prompt, type:
which qcc
The command returns:
C:/ProgramData/MATLAB/SupportPackages/<release>/toolbox/slrealtime/target/supportpackage/qnx700/host/win64/x86_64/usr/bin/qcc.EXE
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'))
The example FMU file vanDerPol_slrt.fmu
contains this
set of folders:
C:\work\my_fmu_work\ C:\work\my_fmu_work\binaries\ C:\work\my_fmu_work\binaries\slrt_x64 C:\work\my_fmu_work\binaries\win64 C:\work\my_fmu_work\documentation C:\work\my_fmu_work\resources C:\work\my_fmu_work\sources\
The example has FMU source files in the sources folder. This example uses
files: fmuTemplate.c
, fmuTemplate.h
,
vanDerPol.c
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
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
.
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
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/vanDerPol.so -fPIC -DFMI_COSIMULATION -IC:/PROGRA~1/MATLAB/R2020b_bash/rtw/c/src/rapid/fmu vanDerPol.c
Note
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.
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 *
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.