undefined reference to `gettimeofday' on ncs v2.5.2

I would like to test the following function on nRF52832 MDK. But west build failed.

uint32_t randGen(void) {
    uint32_t num = 0;
    srand(time(NULL));
    const int x = rand();
    if (x > DATA_MAX) {
        num = DATA_MAX;
    } else {
        num = (uint32_t) x;
    }

    return num;
}

The following are west build error messages.

C:\ncs\v2.5.2\nrf\samples\caf_time_52832>west build -b nrf52832_mdk
[174/179] Linking C executable zephyr\zephyr_pre0.elf
FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map
arm-zephyr-eabi/lib/thumb/v7e-m/nofp\libc.a(libc_time_time.c.o): in function `time':
time.c:(.text.time+0x8): undefined reference to `gettimeofday'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Procedures to reproduce this issue are as follows.

1. Unzipping caf_time_52832.zip to C:\ncs\v2.5.2\nrf\samples folder.

2. cd C:\ncs\v2.5.2\nrf\samples\caf_time_52832
3. west build -b nrf52832_mdk

Related