Nios® II Software Developer Handbook

ID 683525
Date 8/28/2023
Public
Document Table of Contents

5.4.3.6. Configuring Optimization and Debugger Options

By default, the Nios® II SBT creates your project with the correct compiler options for debugging environments. These compiler options turn off code optimization, and generate a symbol table for the debugger.

You can control the optimization and debug level through the project makefile, which determines the compiler options.

Example 4–5. Default Application Makefile Settings

APP_CFLAGS_OPTIMIZATION := -O0
APP_CFLAGS_DEBUG_LEVEL := -g 

When your project is fully debugged and ready for release, you might want to enable optimization and omit the symbol table, to achieve faster, smaller executable code. To enable optimization and turn off the symbol table, edit the application makefile to contain the symbol definitions shown in the following example. The absence of a value on the right hand side of the APP_CFLAGS_DEBUG_LEVEL definition causes the compiler to omit generating a symbol table.

Example 4–6. Application Makefile Settings with Optimization

APP_CFLAGS_OPTIMIZATION := -O3 
APP_CFLAGS_DEBUG_LEVEL := 
Note: When you change compiler options in a makefile, before building the project, run make clean to ensure that all sources are recompiled with the correct flags.

For more information about makefile editing and make clean, refer to the “Applications and Libraries” chapter.