Sometimes as you are developing your application, you may reach the point where the Debug build grows to become too big to fit into the flash on your MCU, whereas the Release build will still fit. In such cases you will see a link error similar to the following:
ld.exe: myapp.axf section .text will not fit in region MFlash8
ld.exe: region MFlash8 overflowed by 356 bytes
collect2: ld returned 1 exit status
make: *** [myapp.axf] Error 1
However switching over to developing using the Release build may not be suitable, due to the constraints put onto the debug view of your code, as discussed in the FAQ on Compiler Optimization.
A solution may be to build certain parts of your application at a higher level of optimization, whilst keeping the areas that you need to actively debug being built for -O0.
One way to do this may be to switch any library projects that your application uses so that they build at a higher optimization level. One good example of this is the CMSIS library project. In most cases you will not need to debug the code within this, so you could change the optimization used by the Debug build of this from -O0 to -Os.
If this still does not produce the code size reduction required, then you could try changing the optimization level used for compiling various files within your main application project. For example you could change the default optimization level for the project from -O0 to -Os, and then change the optimization level of files or groups of files that you are actively going to debug back to -O0.
Note: The LPCXpresso IDE Version 7 ships with a version of the GNU C Compiler 4.8.2 supporting a new option -Og (Optimize with good debugging experience). -Og enables optimizations that do not interfere with debugging. It is intended to be used as the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable level of optimization while maintaining fast compilation and a good debugging experience.
For more information, please see the FAQs on: