sys_rand32_get(); causes build problems

I am trying to modify the threads sample application with the following code:

#include <zephyr/random/rand32.h>

my_sleep_ms=sys_rand32_get();
my_sleep_ms+=sleep_ms;
if (my_sleep_ms > 5000) {my_sleep_ms -= 5000;}

This causes a massive, unintelligible, word salad, error message at build time:

[2/11] Linking C static library app\libapp.a
[3/11] Linking C executable zephyr\zephyr_pre0.elf
FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map
cmd.exe /C "cd . && C:\ncs\toolchains\v2.3.0\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe -gdwarf-4 zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr\zephyr_pre0.elf -Wl,-T zephyr/linker_zephyr_pre0.cmd -Wl,-Map=C:/MyNordic/Apps/threads/build/zephyr/zephyr_pre0.map -Wl,--whole-archive app/libapp.a zephyr/libzephyr.a zephyr/arch/common/libarch__common.a zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a zephyr/lib/libc/minimal/liblib__libc__minimal.a zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a zephyr/soc/arm/nordic_nrf/nrf52/libsoc__arm__nordic_nrf__nrf52.a zephyr/boards/arm/nrf52840dongle_nrf52840/libboards__arm__nrf52840dongle_nrf52840.a zephyr/drivers/clock_control/libdrivers__clock_control.a zephyr/drivers/gpio/libdrivers__gpio.a zephyr/drivers/timer/libdrivers__timer.a zephyr/drivers/pinctrl/libdrivers__pinctrl.a modules/nrf/lib/fatal_error/lib..__nrf__lib__fatal_error.a modules/nrf/drivers/hw_cc310/lib..__nrf__drivers__hw_cc310.a modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a -Wl,--no-whole-archive zephyr/kernel/libkernel.a zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj -L"c:/ncs/toolchains/v2.3.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/thumb/v7e-m/nofp" -LC:/MyNordic/Apps/threads/build/zephyr -lgcc zephyr/arch/common/libisr_tables.a -no-pie -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee -Wl,--gc-sections -Wl,--build-id=none -Wl,--sort-common=descending -Wl,--sort-section=alignment -Wl,-u,_OffsetAbsSyms -Wl,-u,_ConfigAbsSyms -nostdlib -static -Wl,-X -Wl,-N -Wl,--orphan-handling=warn C:/ncs/v2.3.0/nrfxlib/crypto/nrf_cc310_platform/lib/cortex-m4/soft-float/no-interrupts/libnrf_cc310_platform_0.9.16.a && cmd.exe /C "cd /D C:\MyNordic\Apps\threads\build\zephyr && C:\ncs\toolchains\v2.3.0\opt\bin\cmake.exe -E echo ""
c:/ncs/toolchains/v2.3.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.1.0/../../../../arm-zephyr-eabi/bin/ld.exe: app/libapp.a(main.c.obj): in function `sys_rand32_get':
C:\MyNordic\Apps\threads\build\zephyr\include\generated\syscalls\rand32.h:32: undefined reference to `z_impl_sys_rand32_get'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: 'c:\ncs\toolchains\v2.3.0\opt\bin\cmake.EXE' --build 'c:\MyNordic\Apps\threads\build'

* The terminal process terminated with exit code: 1.
* Terminal will be reused by tasks, press any key to close it.

If I modify the code to not include the sys_rand32_get() call as follows:

#include <zephyr/random/rand32.h>

//my_sleep_ms=sys_rand32_get();
my_sleep_ms=sleep_ms;
if (my_sleep_ms > 5000) {my_sleep_ms -= 5000;}

I builds with no errors an executes correctly.

This leads me to believe I don't have my project set up correctly but I have no idea what to do to fix it.  I

s there a maven among you kind enough to lend a hand?

Related