Build Error: main.c:.. error: <KCONFIG_SUMBOL> undeclared here (not in a function)

I was trying to build the Golioth reference-design-can-asset-tracker for the aludel elixir (oh yeah, that’s now supported!). I kept running into errors I didn’t understand and wanted to help light the way for others that might have similar Zephyr build errors in the future. I got an error that looked familiar but I couldn’t figure it out for a while. Do you see it?

chrisg  $   ~/golioth/reference-design-can-asset-tracker  west build -p -b aludel_elixir app
-- west build: making build dir /home/chrisg/golioth/reference-design-can-asset-tracker/build pristine
-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
-- Application: /home/chrisg/golioth/reference-design-can-asset-tracker/app
-- CMake version: 3.28.3
-- Found Python3: /home/chrisg/golioth/reference-design-can-asset-tracker/.venv/bin/python (found suitable version "3.12.3", minimum required is "3.8") found components: Interpreter 
-- Cache files will be written to: /home/chrisg/.cache/zephyr
-- Zephyr version: 3.4.99 (/home/chrisg/golioth/reference-design-can-asset-tracker/deps/zephyr)
-- Found west (found suitable version "1.2.0", minimum required is "0.14.0")
-- Board: aludel_elixir, Revision: B
-- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
-- Found host-tools: zephyr 0.16.4 (/home/chrisg/zephyr-sdk-0.16.4)
-- Found toolchain: zephyr 0.16.4 (/home/chrisg/zephyr-sdk-0.16.4)
-- Found Dtc: /home/chrisg/zephyr-sdk-0.16.4/sysroots/x86_64-pokysdk-linux/usr/bin/dtc (found suitable version "1.6.0", minimum required is "1.4.6") 
-- Found BOARD.dts: /home/chrisg/golioth/reference-design-can-asset-tracker/deps/modules/lib/golioth-boards/boards/arm/aludel_elixir/aludel_elixir.dts
-- Found devicetree overlay: /home/chrisg/golioth/reference-design-can-asset-tracker/deps/modules/lib/golioth-boards/boards/arm/aludel_elixir/aludel_elixir_B.overlay
-- Generated zephyr.dts: /home/chrisg/golioth/reference-design-can-asset-tracker/build/zephyr/zephyr.dts
-- Generated devicetree_generated.h: /home/chrisg/golioth/reference-design-can-asset-tracker/build/zephyr/include/generated/devicetree_generated.h
-- Including generated dts.cmake file: /home/chrisg/golioth/reference-design-can-asset-tracker/build/zephyr/dts.cmake

warning: MBEDTLS_SSL_OUT_CONTENT_LEN (defined at /home/chrisg/golioth/reference-design-can-asset-
tracker/deps/nrf/subsys/nrf_security/Kconfig.tls:298) was assigned the value '2048' but got the
value ''. Check these unsatisfied dependencies: MBEDTLS_TLS_LIBRARY (=n), NRF_SECURITY (=n). See
http://docs.zephyrproject.org/latest/kconfig.html#CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN and/or look up
MBEDTLS_SSL_OUT_CONTENT_LEN in the menuconfig/guiconfig interface. The Application Development
Primer, Setting Configuration Values, and Kconfig - Tips and Best Practices sections of the manual
might be helpful too.


warning: MBEDTLS_SSL_IN_CONTENT_LEN (defined at /home/chrisg/golioth/reference-design-can-asset-
tracker/deps/nrf/subsys/nrf_security/Kconfig.tls:305) was assigned the value '2048' but got the
value ''. Check these unsatisfied dependencies: MBEDTLS_TLS_LIBRARY (=n), NRF_SECURITY (=n). See
http://docs.zephyrproject.org/latest/kconfig.html#CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN and/or look up
MBEDTLS_SSL_IN_CONTENT_LEN in the menuconfig/guiconfig interface. The Application Development
Primer, Setting Configuration Values, and Kconfig - Tips and Best Practices sections of the manual
might be helpful too.


warning: Experimental symbol NET_SOCKETS_SOCKOPT_TLS is enabled.


warning: Experimental symbol NET_SOCKETS_ENABLE_DTLS is enabled.

Parsing /home/chrisg/golioth/reference-design-can-asset-tracker/app/Kconfig
Loaded configuration '/home/chrisg/golioth/reference-design-can-asset-tracker/deps/modules/lib/golioth-boards/boards/arm/aludel_elixir/aludel_elixir_defconfig'
Merged configuration '/home/chrisg/golioth/reference-design-can-asset-tracker/app/prj.conf'
Configuration saved to '/home/chrisg/golioth/reference-design-can-asset-tracker/build/zephyr/.config'
Kconfig header saved to '/home/chrisg/golioth/reference-design-can-asset-tracker/build/zephyr/include/generated/autoconf.h'
-- Found GnuLd: /home/chrisg/zephyr-sdk-0.16.4/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd (found version "2.38") 
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /home/chrisg/zephyr-sdk-0.16.4/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
CMake Warning at /home/chrisg/golioth/reference-design-can-asset-tracker/deps/modules/lib/golioth-firmware-sdk/examples/zephyr/common/CMakeLists.txt:10 (message):
  WARNING: Using CONFIG_GOLIOTH_SAMPLE_COMMON=y with external application
  code.  This option is supposed to be used only from projects in
  /home/chrisg/golioth/reference-design-can-asset-tracker/deps/modules/lib/golioth-firmware-sdk/examples/


          


-- Configuring done (2.5s)
-- Generating done (0.1s)
-- Build files have been written to: /home/chrisg/golioth/reference-design-can-asset-tracker/build
-- west build: building application
[1/378] Preparing syscall dependency handling

[3/378] Generating include/generated/version.h
-- Zephyr version: 3.4.99 (/home/chrisg/golioth/reference-design-can-asset-tracker/deps/zephyr), build: v3.4.99-ncs1-2
[28/378] Building C object CMakeFiles/app.dir/src/main.c.obj
FAILED: CMakeFiles/app.dir/src/main.c.obj 
ccache /home/chrisg/zephyr-sdk-0.16.4/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -DKERNEL -DMBEDTLS_CONFIG_FILE=\"config-tls-generic.h\" -DNRF9160_XXAA -DNRF_SKIP_FICR_NS_COPY_TO_RAM -DPICOLIBC_INTEGER_PRINTF_SCANF -DZCBOR_VARIANCE -DZCBOR_VERSION_MAJOR=0 -DZCBOR_VERSION_MINOR=7 -D_FORTIFY_SOURCE=1 -D_POSIX_C_SOURCE=200809 -D__LINUX_ERRNO_EXTENSIONS__ -D__PROGRAM_START -D__ZEPHYR__=1 -Dtimegm=mktime -I/home/chrisg/golioth/reference-design-can-asset-tracker/app/src/lib/inc -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/zephyr/include -I/home/chrisg/golioth/reference-design-can-asset-tracker/build/zephyr/include/generated -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/zephyr/soc/arm/nordic_nrf/nrf91 -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/zephyr/lib/posix/getopt/. -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/zephyr/soc/arm/nordic_nrf/common/. -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/zephyr/subsys/net/lib/coap/. -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/zephyr/subsys/net/lib/sockets/. -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/zephyr/subsys/net/lib/tls_credentials/. -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/zephyr/subsys/net/lib/dns/. -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/zephyr/subsys/settings/include -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/modules/lib/golioth-firmware-sdk/port/zephyr/include -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/modules/lib/golioth-firmware-sdk/port/zephyr/../../include -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/modules/lib/golioth-firmware-sdk/examples/zephyr/common/include -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/modules/lib/golioth-firmware-sdk/port/zephyr/include_random -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/modules/lib/network-info/include -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/nrf/include -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/nrf/tests/include -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/modules/hal/cmsis/CMSIS/Core/Include -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/zephyr/modules/cmsis/. -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/modules/hal/nordic/nrfx -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/modules/hal/nordic/nrfx/drivers/include -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/modules/hal/nordic/nrfx/mdk -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/zephyr/modules/hal_nordic/nrfx/. -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/modules/lib/zcbor/include -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/modules/crypto/mbedtls/include -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/zephyr/modules/mbedtls/configs -I/home/chrisg/golioth/reference-design-can-asset-tracker/deps/zephyr/modules/mbedtls/include -isystem /home/chrisg/golioth/reference-design-can-asset-tracker/deps/nrfxlib/crypto/nrf_cc310_platform/include -fno-strict-aliasing -Os -imacros /home/chrisg/golioth/reference-design-can-asset-tracker/build/zephyr/include/generated/autoconf.h -fno-printf-return-value -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m33 -mthumb -mabi=aapcs -mfp16-format=ieee --sysroot=/home/chrisg/zephyr-sdk-0.16.4/arm-zephyr-eabi/arm-zephyr-eabi -imacros /home/chrisg/golioth/reference-design-can-asset-tracker/deps/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -ftls-model=local-exec -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=/home/chrisg/golioth/reference-design-can-asset-tracker/app=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/chrisg/golioth/reference-design-can-asset-tracker/deps/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/home/chrisg/golioth/reference-design-can-asset-tracker=WEST_TOPDIR -ffunction-sections -fdata-sections --specs=picolibc.specs -D_POSIX_THREADS -std=c99 -MD -MT CMakeFiles/app.dir/src/main.c.obj -MF CMakeFiles/app.dir/src/main.c.obj.d -o CMakeFiles/app.dir/src/main.c.obj -c /home/chrisg/golioth/reference-design-can-asset-tracker/app/src/main.c
/home/chrisg/golioth/reference-design-can-asset-tracker/app/src/main.c:37:39: error: 'CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION' undeclared here (not in a function)
   37 | static const char *_current_version = CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION;

[ ... errors continue for many pages]

I will “solve” the answer below for my own edification and also to help others in the future.

The board in question (Aludel Elixir) is supported and tested in this project. It’s why I was so suprised that the latest release build failed. The beginning of the pages and pages of errors started with this line:

/home/chrisg/golioth/reference-design-can-asset-tracker/app/src/main.c:37:39: error: 'CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION' undeclared here (not in a function) 37 | static const char *_current_version = CONFIG_MCUBOOT_IMGTOOL_SIGN_VERSION;

But that is a custom KConfig symbol that we have used many times before. It basically allows us to call out the firmware version of the build in prj.confand then we pass that to mcuboot during the build and display it on the terminal during boot time, as well as passing the firmware version to the aludel ostentus epaper display (useful!)

The solution

So what was my error?

Note the build command that I issued:

west build -p -b aludel_elixir app

That is missing a critical piece, namely the “_ns” (soon to be “/ns” in future versions of Zephyr). That stands for “non-secure”. This one builds just fine

west build -p -b aludel_elixir_ns app

since we’re compiling for the nRF9160 there is a secure and a nonsecure version of the firmware. All Golioth applications are built for the non-secure side of the processor pair (dual Cortex-M33) because the secure side is used for the modem and controlling the LTE-M / NB-IOT capabilities of the SOM. When I forgot to add the “_ns”, I was trying to compile for an entirely different processor. It didn’t give me a clearer error because aludel_elixir does (and needs to) exist. What I should have done is follow the great guide in the README and copy/pasted the build command :smiley:

In summary: