S-function and Custom C Code support with Simulink Desktop Real-Time (SLDRT) in Kernel Mode
조회 수: 28 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2020년 5월 26일
편집: MathWorks Support Team
2025년 6월 24일
I have written a C-MEX S-function, or other custom C code that uses Windows API functions. When I try to compile this model using sldrt.tlc to run the real-time simulation with Simulink Desktop Real-Time (SLDRT) in Kernel Mode (previously called External Mode), I receive the following build error using MATLAB R2020a:
In file included from ...\someSource.c:134:
C:/PROGRA~1/MATLAB/R2020a/toolbox/sldrt/lib/include\Windows.h:16:2: error:
Attempt to include "windows.h"
C:/PROGRA~1/MATLAB/R2020a/toolbox/sldrt/lib/include\Windows.h:17:2: error:
The model being compiled contains a block that can run on host only and
cannot be compiled for External Mode. Please either switch to Normal Mode
or remove the block.
In newer versions of MATLAB:
In file included from someSourcec:21:
In file included from ./someSource.h:25:
C:/PROGRA~1/MATLAB/R2024b/toolbox/sldrt/lib/include\windows.h:16:2: error:
The model contains a block that requires to include the "windows.h" header
in its generated code. Such blocks cannot be compiled for Run in Kernel Mode.
Please either switch to Connected IO Mode or remove the block.
When I include an S-Function or other custom external C code in my model, is there a limitation regarding the C library functions it can use with Simulink Desktop Real-Time simulation in External Mode?
채택된 답변
MathWorks Support Team
2025년 6월 24일
편집: MathWorks Support Team
2025년 6월 24일
You can use S-functions and custom C code with SLDRT Kernel Mode, as long as the code is self-contained. This means the S-functions and C code should only rely on a limited subset of the standard C library, such as math and string functions.
S-functions or custom C code that use file input/output, console input/output, or any Windows API calls, such as those from the windows.h header, are not supported in SLDRT Kernel Mode.
For a detailed list of supported and unsupported C functions, refer to the official documentation:
Note that the above limitations apply only to SLDRT Kernel Mode. They do not affect Connected IO or Accelerator Mode simulations. So, if your S-function or custom C code requires unsupported features such as the windows.h header, you can still simulate your model using Connected IO or Accelerator Mode. For more information about the different SLDRT simulation modes, see this MATLAB Answers article:
Also note that the ability to simulate an S-function or custom C code with other code generation targets—such as grt.tlc, ert.tlc—does not guarantee compatibility with sldrt.tlc. For example, S-functions that depend on dynamically linked libraries (DLLs) typically do not work with SLDRT, as the real-time kernel cannot access these DLLs.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!