Troubleshoot Long Build Times for Real-Time Application
The model build process for a Simscape™ Multibody™ models is slow and uses an unexpected amount of memory.
What This Issue Means
The default QNX® Neutrino® compiler switches for Simulink® Real-Time™ apply optimizations that lead to long build times or slow builds for some complex models, such as Simscape Multibody models.
Try This Workaround
To improve the real-time application build speed, change the compiler switch
            selections from the default selections by adding the
                -fdisable-rtl-sched2 switch for the C/C++ compiler:
- Open your Simulink Real-Time model. 
- In the Simulink Editor, from the Real-Time tab, select Hardware Settings. 
- Select Code Generation > Build configuration > Specify 
- Click the C Compiler options and add option - -fdisable-rtl-sched2.
- Click the C++ Compiler options and add option - -fdisable-rtl-sched2.
- Click Apply and OK. 
After updating the compiler options, the options appear as shown.

If you prefer to use a programmatic approach to update these compiler switches, you could use this code.
% add a compiler flag '-fdisable-rtl-sched2' set_param(modelName, 'BuildConfiguration', 'Specify'); options = get_param(modelName, 'CustomToolchainOptions'); ccompiler_idx = find(strcmp(options, 'C Compiler')); cppcompiler_idx = find(strcmp(options, 'C++ Compiler')); options{ccompiler_idx+1} = ... [options{ccompiler_idx+1} ' -fdisable-rtl-sched2']; options{cppcompiler_idx+1} = ... [options{cppcompiler_idx+1} ' -fdisable-rtl-sched2']; set_param(modelName, 'CustomToolchainOptions', options);