Build an Application

The Zephyr build system compiles and links all components of an application into a single application image that can be run on simulated hardware or real hardware.

Building an Application

The build system allows you to easily build an application using the application’s existing configuration. However, you can also build it using different configuration settings, if desired.

Before you begin

  • Ensure you have added all application-specific code to the application directory, as described in Add Application-Specific Code. Ensure each source code directory and sub-directory has its own Makefile.
  • Ensure you have configured the application’s kernel, as described in Configure an Application’s Kernel.
  • Ensure the Zephyr environment variables are set for each console terminal; see Common Procedures.

Steps

  1. Navigate to the application directory ~/appDir.

  2. Enter the following command to build the application’s zephyr.elf image using the configuration settings for the board type specified in the application’s Makefile.

    $ make
    

    If desired, you can build the application using the configuration settings specified in an alternate .conf file using the CONF_FILE parameter. These settings will override the settings in the application’s .config file or its default .conf file. For example:

    $ make CONF_FILE=prj.alternate.conf
    

    If desired, you can build the application for a different board type than the one specified in the application’s Makefile using the BOARD parameter. For example:

    $ make BOARD=arduino_101
    

    Both the CONF_FILE and BOARD parameters can be specified when building the application.

Rebuilding an Application

Application development is usually fastest when changes are continually tested. Frequently rebuilding your application makes debugging less painful as the application becomes more complex. It’s usually a good idea to rebuild and test after any major changes to the application’s source files, Makefiles, or configuration settings.

Important

The Zephyr build system rebuilds only the parts of the application image potentially affected by the changes. Consequently, rebuilding an application is often significantly faster than building it the first time.

Steps

  1. Follow the steps specified in Building an Application above.

Recovering from a Build Failure

Sometimes the build system doesn’t rebuild the application correctly because it fails to recompile one or more necessary files. You can force the build system to rebuild the entire application from scratch with the following procedure:

Steps

  1. Navigate to the application directory ~/appDir.

  2. Enter the following command to delete the application’s generated files for the specified board type, except for the .config file that contains the application’s current configuration information.

    $ make [BOARD=<type>] clean
    

    Alternatively, enter the following command to delete all generated files for all board types, including the .config files that contain the application’s current configuration information for those board types.

    $ make pristine
    
  3. Rebuild the application normally following the steps specified in Building an Application above.