MATLAB: Including source files in s-function gateway file

include sourcesimulink

I am attempting to "include" a "xxx.c" file in the top s-function file that gets compiled into a ".mexw32" file. The file has the normal boiler-plate functions in it like :
static void mdlInitializeSizes( SimStruct *S ) static void mdlInitializeSampleTimes( SimStruct *S )
Etc etc
At the top of the file it looks like:
#define S_FUNCTION_NAME s_simulation #define S_FUNCTION_LEVEL 2
/******************/ /* / / INCLUDED FILES / / / /*****************/
/* reference appropriate header files */ #include "../simulation.h"
#include "../ChekFile.c" #include "../ChekFile2.c"
The header file is part of the code that currently functions OK but the last two lines do not seem to get used because when I use "dumpbin" to look in the ".mexw32" file I can't find any of the subroutines and the size of the ".mexw32" file doesn't change no matter how big I make the code for the ChekFile.c subroutines. I put calls to the subroutines in some of the boiler-plate subroutines but there doesn't seem to be a reference to them in the final ".mexw32" file.

Best Answer

What dumpbin flags are you using to examine the MEX binary? I think dumpbin only displays exported functions from a DLL. Ordinarily, in a MEX-function, only the gateway function called mexFunction() is exported (the export keyword is added in mex.h). For S-functions, this is not so obvious because Simulink adds some additional instrumentation around the mdlXXX functions (this is in simulink.c, which is included at the end of all S-functions) and calls them from a mexFunction - thus, it does conform to the interface of any other MEX-function.
So if you have included source files in your S-function and are able to compile and run it successfully (I presume you already test this by calling them from one of the mdlXXX functions), you can rest assured that they have indeed been included in the MEX binary.