C Caller
Integrate C code in Simulink
Libraries:
Simulink /
User-Defined Functions
Description
The C Caller block integrates your external C code into Simulink®. This block imports and lists the functions in your external C code, and enables you to select your resolved C functions to integrate in your Simulink models.
Fetch a C Caller block to the Simulink canvas, using Library Browser > Simulink > User Defined Functions.
Then, click the
icon on the block dialog box. This opens the
Configuration Parameters dialog box. Inside the
Configuration Parameters dialog box, go to the
Simulation Target pane and use the parameters in the
Code information tab to define source code and any supporting
files. To browse the function definitions in your source code, use the
icon. For more information about defining source code and
supporting files, see Specify and Configure Custom C/C++ Code.
To change your source code and the supporting files, use the same parameters in the
Code information tab of the Simulation
Target pane in the Configuration Parameters dialog
box. After changing your source code and the supporting files, refresh the list of functions
by clicking the
icon on the block dialog box.
Examples
Limitations
Initialization/Termination of Custom Code Settings — If you need to allocate and deallocate memory for your custom code, insert allocate and deallocate in the Initialize function and Terminate function fields of custom code settings, or use a C Function block.
Complex Data Support — The block does not support complex data types in Simulink.
Variable Arguments — Variable arguments in C are not supported, for example,
int sprintf(char *str, const char *format, ...).C++ Syntax — The block does not support native C++ syntax directly. You need to write a C function wrapper to interface with C++ code.
Simulink Test™ Observer Support — Starting in R2026a, you can observe exported global variables in a C Caller block using Observer Port and Observer Reference blocks. You cannot use these blocks to observe static global variables or global variables of n-D matrices.
Ports
Input
Output
Parameters
Block Characteristics
More About
Tips
To test models that include C Caller blocks, see Test Integrated C Code (Simulink Test).
If a model has custom code, after the model is updated or run, the
slprjfolder may be locked due to the loaded custom code simulation executable file. You cannot delete the folder when it is locked. To unload the executable file and unlock theslprjfolder, use theclear mexcommand. Seeclear.
Extended Capabilities
Version History
Introduced in R2018bSee Also
Blocks
- C Function | MATLAB Function | MATLAB System | S-Function | S-Function Builder | Observer Reference (Simulink Test) | Observer Port (Simulink Test)





