Export c++ code from simulink scheme with s-function

조회 수: 19 (최근 30일)
dario zurlo
dario zurlo 2022년 2월 5일
답변: Srija Kethiri 2023년 1월 16일
Hello everyone,
I have a simulink working simulink schema in which there are some s-function, I want to export this code in c++ and compile it. I already tried to export and compile a simple schema and it works, but when i try to compile the exported code of my project I get a lot of errors like
error: #error Unrecognized use
error: #error Must define one of RT, NRT, MATLAB_MEX_FILE, SL_INTERNAL, or FIPXT_SHARED_MODULE
error: #error Unhandled case
error: mxArraydoes not name a type mxArray **dlgParams; /* The S-function parameters
error: mxArrayhas not been declared mxArray **)
error: mxArraydoes not name a type mxArray *propVal;
error: RTWSfcnInfodoes not name a type; did you mean ‘RTWLogInfo’? RTWSfcnInfo sfcnInfo
The main settings that i used are:
Code generation system target file --> grt.tlc
language --> C++
Pack code and artifact --> <name_zip>
Tool chain GNU gcc/g++ | gmake (64-bit Linux)
default parameter behavior --> tuanble
code interface packaging --> nonreusable function
external mode --> chcked
standar math library --> c++ 03(ISO)
single output/update function --> checked
i used a fixed step size solver
Im using Ubuntu 18.
The source is generated succesfully the problem is when i try to compile the code.
Once the code is generate I get a zip folder with all the sources and also some external header file that I include when I make the CMakeLists.txt. I also tryied to compile directly the code with the .mk file but also I get a bounch of errors. The problem is realated with the s-function because I built a simple simulink schema with a source an s-function that implements a dynamical model and an output and when i generate the code and compile it I get the same errors. I also tryied to make a simple schema without s-function and this works. So is there any settings for the s-function to be exportable?

답변 (1개)

Srija Kethiri
Srija Kethiri 2023년 1월 16일
Hi Dario,
From my understanding, you are trying to generate the code for your model which has a s-function in it. When you are compiling the exported code getting an error.
This issue has several possible root causes. Here are some troubleshooting steps you can try to find the root cause of the issue.
1. Does the S-Function use TLC inlining files but also has the parameter "S-function modules" set to a specific file name?
If an S-Function has TLC inlining files, then the S-Function block parameter "S-function modules" should be left blank.
  • If the "S-function modules" parameter is set to the name of MEX source code for the S-function, this will introduce non-inlined MEX source code into the build process.
  • This results in an error message because the build process saw that the S-Functions were inlined with TLC, so it didn't put the -DRT onto the compile line.
  • Refer to the following documentation page for more information: https://www.mathworks.com/help/ecoder/ug/inlining-s-functions.html
2. Did the C/C++ MEX S-Function file contain the following preprocessor directive?
This should be removed from the C/C++ MEX S-Function file.
3. If you are you trying to build the code in an external IDE then please
Try the following troubleshooting steps:
  • Make sure the required defines are set properly. You can find the required defines in the "defines.txt" text file in your model's code generation directory.
  • Check to see if any compiler flags (for example RT or USE_RTMODEL) should be added to the external IDE.
  • Check that the following folder is included by the external IDE:
Hope this helps!


Help CenterFile Exchange에서 Simulink Coder에 대해 자세히 알아보기




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by