problem of including header files in c code file for simulink s-function

13 views (last 30 days)
Hi,
I'm trying to copy an example "sfun_zc.c" of the "S-function examples" from the matlab help center website: https://www.mathworks.com/help/simulink/sfg/s-function-examples.html
When I copy this example in new project in the visual studio there are errors saying that many header files like "simstrc.h" do not exist. So I inlcude all directories of the non available files via the project properties. That worked, however it seems that including new directories introducing new errors or there is still some unresolved problems, and I have here two problems:
  1. Error: identifier "mwSize" is undefined from file "rt_matrx.h"
  2. Error: #error directive: Must define one of RT, NRT, MATLAB_MEX_FILE, SL_INTERNAL, or FIPXT_SHARED_MODULE from file "simstruc_compcond.h"
Thank you!

Answers (1)

Vidip
Vidip on 7 Jun 2024
The error message you're encountering, 'Must define one of RT, NRT, MATLAB_MEX_FILE, SL_INTERNAL, or FIPXT_SHARED_MODULE', typically occurs during the compilation of MATLAB MEX files or Simulink models that interface with C/C++ code.
This issue has several possible root causes. Here are some troubleshooting steps you can try to find the root cause of the issue:
  1. If an S-Function has TLC inlining files, then the "S-function modules" parameter in the S-Function block should be left blank. Setting the "S-function modules" parameter to the name of MEX source code for the S-Function introduces non-inline MEX source code into the build process. This results in an error message because the build process recognizes that the S-Functions were inline with TLC, so it doesn't include the -DRT on the compile line.
  2. If the C/C++ MEX S-Function file contain the ‘#define MATLAB_MEX_FILE’ preprocessor directive, then this directive should be removed from the C/C++ MEX S-Function file. The definition will automatically be included in the compiler arguments when the MEX file is built. For information on creating a C MEX S-Function, refer to the following documentation page: https://in.mathworks.com/help/simulink/sfg/example-of-a-basic-c-mex-s-function.html
  3. If you are attempting to build the code in an external IDE and receiving these error messages, then try to ensure the required defines are set properly. You can find the required defines in the 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 and verify that the following folder is included by the external IDE: <matlabroot>\extern\include

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!