Clear Filters
Clear Filters

c-mex S-Function error in desktop real-time external mode: Error occurred while executing External Mode MEX-file 'sldrtext': Error loading real-time image: undefined symbol

2 views (last 30 days)
I have encountered some issues with an S-Function I developed using c-mex. The purpose of my S-Function is to add two inputs together, and I have implemented this functionality using external c source code and header files. Here are the contents of these files:
myadd.h
int myadd(int a, int b);
myadd.c
#include "myadd.h"
int myadd(int a, int b)
{
return a+b;
}
and my S-Function is mysfun.c, its output function is:
static void mdlOutputs(SimStruct *S, int_T tid)
{
const real_T *u = (const real_T*) ssGetInputPortSignal(S,0);
real_T *y = ssGetOutputPortSignal(S,0);
y[0] = myadd((int)u[0],10);
}
I compiled them along with my S-Function using the following command:
mex mysfun.c myadd.c
The compilation process showed no errors. Next, I tested the S-Function in normal mode in Simulink, and it indeed worked properly. However, when I switched to Simulink Desktop Real-Time's external mode, I encountered the following error message:
'''
Error occurred while executing External Mode MEX-file 'sldrtext': Error loading real-time image: undefined symbol "myadd"
'''
But when I implement myadd() function directly in mysfun.c, like:
int myadd(int a, int b)
{
return a+b;
}
static void mdlOutputs(SimStruct *S, int_T tid)
{
const real_T *u = (const real_T*) ssGetInputPortSignal(S,0);
real_T *y = ssGetOutputPortSignal(S,0);
y[0] = myadd((int)u[0],10);
}
the execution in external mode worked properly. I have no idea what is the problem.
Could someone please help me understand this error message? Thank you!

Accepted Answer

Jan Houska
Jan Houska on 24 May 2024
Hi You-Cheng,
this is because the external mode build system does not know that it should include the file myadd.c to the list of files needed to build the real-time executable. Please see here how to add custom files to the build process, especially see the Specify Additional Source Files for an S-Function section and the S-function modules parameter of the S-function block.
Good Luck, Jan

More Answers (0)

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!