Search code examples
c++embeddedclockatmelstudio

Calling `clock()` gives an error: undefined reference to `_times'


I'm trying to use the clock() function in my C++ code but it's not working. I've tried adding #include <time.h> or #include <ctime> but it hasn't helped. I'm using Atmel Studio.

#include <time.h>

int main(void)
{
        clock_t myClock = clock();
}

There shouldn't be an error, but I'm getting the following error messages:

recipe for target 'SAMS70.elf' failed
undefined reference to `_times'
ld returned 1 exit status

Does anyone have an idea why this might be happening?


Solution

  • MCU's normally do not expose processor use time. A library clock function calls the expected _times function to get the value, but the function is not defined for MCU for the reason stated above.