By "normal compiler" I presume you mean the native compiler for your host system? In that case the development host is standard hardware with an operating system that provides "wall-clock" time through operating services that ultimately get time from the RTC or NTP.
In embedded systems the standard library is generic and needs to be retargeted to your platform. Typically I/O, heap management and time services need retargeting. In this case you need to define clock_gettime()
to resolve the link (or simply redefine an override for time()
- as described here). How you implement it will depend on your specific hardware. Typically you would get time from the RTC, but if your hardware lacks an RTC crystal and a battery backup thereof, it will serve little purpose. Time has to come from somewhere, and the library cannot determine where for your specific hardware.
If you actually never need wall-clock time and are simply following the common idiom of using time(NULL)
as a random number generator seed, then rather then fully supporting a time()
function you don't need; consider an alternative means of generating a seed such as that described in this Application Note which uses two independent clock sources (VLO and DCO) to generate a random bit sequence. The method is time consuming, so you would normally do it once, then use that as a seed for the standard PRNG via srand()
.
There is an implementation of the App Note algorithm at https://github.com/0/msp430-rng/blob/master/rand.c, but it is implemented as an override for the standard rand()
. I recommend you rename to something like generate_seed()
, then call:
srand( generate_seed() ) ;