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 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
采纳的回答
Jan Houska
2024-5-24
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Target Computer Setup 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!