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:
Enter the folder where the generated code is located (e.g. modelname_ert_rtw)
Open the make file which is located in the directory (e.g. modelname.mk)
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:
A stack are allocated to each function by the operating system and there is no direct way to change the stack size.
Typically, the best way to avoid stack overflow issues would be to change the code in such a way that the variable sizes are not too large to be handled by a single function.
When using Microsoft Visual Studio, you can try setting the compiler flags /F and /STACK in MEXOPTS.BAT file or a compiler specific options file to request the operating system for a larger stack.
The error message is due to a limitation with the Microsoft compiler running out of stack. For more information about the Microsoft compiler error C1063, please refer to following online documentation:
The root cause is that the code generated from a large Simulink model is too big and variables that are stored during compilation may end up using all of compiler stack. The default compiler stack size is 1 MB for a Microsoft compiler. Increasing the compiler stack size will resolve this error message.
The following are few way to increase compiler stack size:
1) Use EDITBIN on the "cl.exe" file to update the stack size as follows:
Open a command prompt as administrator mode from the following path:
Start > Microsoft Windows SDK 7.1 -> Open 'Windows SDK 7.1 Command Prompt'
In the command prompt, navigate to the path of the compiler used in Simulink:
>> cd C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin
Execute the following command to set the increase stack size:
>> editbin /STACK:10000000 cl.exe
>> cd amd64
>> editbin /STACK:10000000 cl.exe
2) Use Compiler flag - '/F <stack size>'
Go to 'Configuration Parameter > Code Generation > Build Process > Build Configuration'. Set this option to 'Specify'
Add '/F <stack size>' to 'C Compiler' options
For additional information, please refer to following:
Best Answer