MATLAB: How to initialize SimStruct from C code

rtws-functionsimulink coder

I exported my Simulink model to C code by using "rtwsfcn.tlc". The output code for the S-Function was generated successfully.
Now I want to import this S function directly in a C project. So what I did is something like this.
SimStruct *S = (SimStruct *)malloc(sizeof(SimStruct));
mdlInitializeSizes(S); … …
But it gives some runtime error. Can anyone tell me the proper way to initialize SimStruct directly in C without using Matlab?

Best Answer

What is your C project ? Is it a embedded project ?
s-function is matlab specific c code which uses lots of function from it library called SimStruct library. It is very difficult and unnecessary to integrate the s-function code into some user project.
Instead twsfcn.tlc, you can use ert.tlc (Embedded coder tool) to generate production quality C code which can be integrated into any custom project.
Related Question