MATLAB: Does Microsoft Visual Studio throw an error about “exceeded object file format limit” when I try to compile a model

acceleratorbigobjcodecompilationcompilererrorgenerationrapidsimulinksimulink coder

I have a very large model and when I try to generate code and compile model, I get an error from Microsoft Visual Studio as below:
error C1128: number of sections exceeded object file format limit : compile with /bigobj
NMAKE : fatal error U1077: '"c:\program files\microsoft visual studio 9.0\VC\BIN\cl.EXE"' : return code '0x1'
Stop.

Best Answer

This error is thrown if the object file is too large for Visual Studio to handle.
As workaround, pass the "/bigobj" flag to the compiler (see https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/fatal-error-c1128?view=vs-2019) in the makefile for the target.
There are two main ways of achieving this:
  1. For example, if the model is using "ert_vc.tmf", then make a copy of this file and change the compiler options. Save the modified file with a different name on the MATLAB path and use it in the "Template makefile" option in the Code Generation pane of the model Configuration Parameters. For more information on template makefiles see the following page of the documentation:* https://www.mathworks.com/help/rtw/ref/template-makefile.html
  2. Create a custom '<STF>_make_rtw_hook' file, such that the flag "/bigobj" is automatically added to the compilation process during the "before_make", by following the documentation below and refer to the attached M-file:* https://www.mathworks.com/help/rtw/ug/customizing-the-target-build-process-with-the-stf-make-rtw-hook-file.html
NOTE: Please do not modify any shipped file. If you need to customize it, always make a copy and then use the copy so that other models using the shipped file are not affected.
A long term solution for this issue would be to use Model Referencing in order to divide the model into smaller parts. As a result, smaller files are generated during code generation process and resources requirements during compile time are reduced.
For details on Model Referencing see: