MATLAB: When does the model fail to initialize in the compiled executable

binarycodecompilerEmbedded Coderexecutablegenerationinitializationissueoverflowstack

After generating my code and compiling it, I have noticed that my model does not complete the initialization step.
Why does this happen?

Best Answer

This issue arises due to the complexity of the model and the generated code. Because the model is very complex, the generated functions require more of the stack than what is available thus causing a stack overflow.
 
To work around this issue, please follow the subsequent steps:
  1.  Enter the folder where the generated code is located (e.g. modelname_ert_rtw)
  2.  Open the make file which is located in the directory (e.g. modelname.mk)
  3. Look for the line that has LDFLAGS and add the appropriate flag to increase the stack size. The flag to increase the stack size depends on which compiler you have:
 For Visual Studio: 
/STACK:8388608,8388608
For MinGW:
-Wl,-stack,0x800000