Building an application

For simplicity, this guide will refer to both samples and applications as “applications”.

After you have created an application, you need to build it in order to be able to program it. Just as for creating the application, you can build the application using either the nRF Connect for VS Code extension or the command line.

For instructions about building with the nRF Connect for VS Code extension, see How to build an application in the extension documentation.

By default, the extension runs both stages of the CMake build (configuration phase and building phase). If you want to only set up the build configuration without building it, make sure the Build after generating configuration is not selected.

To build with Sysbuild, select the Use sysbuild checkbox.

If you want to build with custom options or scripts, read about Binding custom tasks to actions in the extension documentation.

Note

Some samples in the nRF Connect SDK are currently not designed to work out-of-tree. You may need to manually configure your sample to work correctly in the nRF Connect for VS Code extension.

For more information about files generated as output of the build process, see Output build files (image files).

Note

On Windows, because of the Windows path length limitations, the build can fail with errors related to permissions or missing files if some paths in the build are too long. To avoid this issue, shorten the build folder name, for example to build, or shorten the path to the build folder in some other way.

Advanced building procedures

You can customize the basic building procedures in a variety of ways, depending on the configuration of your project.

Advanced compiler settings

The application has full control over the build process.

Using Zephyr’s configuration options is the standard way of controlling how the system is built. These options can be found under Zephyr’s menuconfig Build and Link Features > Compiler Options. For example, to turn off optimizations, select CONFIG_NO_OPTIMIZATIONS.

Compiler options not controlled by the Zephyr build system can be controlled through the CONFIG_COMPILER_OPT Kconfig option.

Common sample components for development

Code found in the samples/common are not intended to be used independently, but in addition to other compatible samples for development purposes. For example, the file path samples/common/mcumgr_bt_ota_dfu contains the source for the CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU Kconfig option. This Kconfig option can be used with specific Nordic Semiconductor devices to enable MCUmgr to perform firmware over-the-air (FOTA) updates using Bluetooth® Low Energy.

To learn more about how to use the CONFIG_NCS_SAMPLE_MCUMGR_BT_OTA_DFU Kconfig option, see the respective device guides for nRF52 Series and the nRF5340 DK.

Optional build parameters

You can customize the basic west build command in a variety of ways. The following table contains some of the commonly used parameters in the nRF Connect SDK.

For more options, see Zephyr’s Building: west build or run the west --help and west build --help commands.

The parameters and options passed in the command line always take precedence over west config settings.

Optional build parameters (selection)

Parameter

Usage

Example

Custom CMake options

Provide additional options for building your application to the CMake process.

See the dedicated section

--no-sysbuild

Explicitly build without Sysbuild. (In the nRF Connect SDK, building with sysbuild is enabled by default.)

west build -b nrf52840dk/nrf52840 --no-sysbuild

-vvv

Enable a detailed Verbose Builds log, which includes the full commands used by the build system to generate the Output build files (image files).

west build -b nrf52840dk/nrf52840 -vvv

directory_name

Build from a directory other than the current directory.

west build -b nrf5340dk/nrf5340/cpuapp/ns nrf/samples/tfm/tfm_psa_template

-d

Specify the build directory where the Output build files (image files) are to be placed. If not specified, the build files are automatically generated in build/zephyr/.

west build -b nrf52840dk/nrf52840 -d local_build

--domain

Build for a single domain in a multi-domain build. This parameter can also be used for programming and debugging multiple domains.

west build -b nrf52840dk/nrf52840 --domain hello_world

menuconfig

Start menuconfig to configure your application’s Kconfig options.

west build -t menuconfig

-p=auto

Reuse an existing build directory for building another application for another board or board target.

west build -b nrf52840dk/nrf52840 -p=auto

test

Run unit tests with the west command from the unit test directory (with the testcase.yaml file).

west build -b native_sim -t run