Undefined reference to `clock_gettime'

Hello!
I’ve setup cross compile environment using Eclipse according to the guide here.

In this code:

`
#include “Timer.h”
#include <time.h>

unsigned long millis(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts );
return ( ts.tv_sec * 1000 + ts.tv_nsec / 1000000L );
}
`

`
#ifndef TIMER_H_
#define TIMER_H_

#define CLOCK_MONOTONIC 1

unsigned long millis ();

#endif /* TIMER_H_ */
`

I have error:

undefined reference to `clock_gettime’

Another libraries work fine (for example stdio.h, iostream …), but time.h is not.

Help, please.
Thanks

Hi,

You need to link you application with -lrt.

/Daniel

In “Tool Settings” > “GCC C++ Linker” in “All option:” I have:

-L/usr/arm-linux-gnueabihf/lib -lrt

All right?
But doesn’t compile…

#include <sys/time.h>

Consider the configuration. You need to do it for Release and Debug configuration.

Perhaps you set it in Debug configuration but you are building a Release version.

Not work…
I tried some links to libraries, but to no avail.

No. I check configuration, all right.
I compiled my project befor added time.h and clock_gettime. Project include many libraries and I hadn’t problems.
Problem is only in clock_gettime.

“Tool Settings” > “GCC C++ Linker” > “Libraries” > “Libraries (-l)” > “Add …” rt.
Problem fixed. Thanks for all.

Worked, thanks Ivan!