Undefined reference to `clock_gettime'

854 views
Skip to first unread message

tvv...@gmail.com

unread,
Oct 4, 2013, 9:30:06 AM10/4/13
to beagl...@googlegroups.com
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

Daniel Nilsson

unread,
Oct 4, 2013, 10:32:48 AM10/4/13
to beagl...@googlegroups.com
Hi,

You need to link you application with -lrt.

/Daniel

tvv...@gmail.com

unread,
Oct 4, 2013, 10:53:29 AM10/4/13
to beagl...@googlegroups.com
In "Tool Settings" > "GCC C++ Linker" in "All option:" I have:

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

All right?
But doesn't compile...

пятница, 4 октября 2013 г., 18:32:48 UTC+4 пользователь Daniel Nilsson написал:

Dieter Wirz

unread,
Oct 4, 2013, 11:14:31 AM10/4/13
to beagl...@googlegroups.com
#include <sys/time.h>
> --
> For more options, visit http://beagleboard.org/discuss
> ---
> You received this message because you are subscribed to the Google Groups
> "BeagleBoard" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to beagleboard...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Tux Leonard

unread,
Oct 4, 2013, 11:21:21 AM10/4/13
to beagl...@googlegroups.com
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.


2013/10/4 <tvv...@gmail.com>

--

tvv...@gmail.com

unread,
Oct 4, 2013, 11:26:35 AM10/4/13
to beagl...@googlegroups.com
Not work...
I tried some links to libraries, but to no avail.

пятница, 4 октября 2013 г., 19:14:31 UTC+4 пользователь Dieter Wirz написал:

tvv...@gmail.com

unread,
Oct 4, 2013, 11:37:01 AM10/4/13
to beagl...@googlegroups.com
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.

пятница, 4 октября 2013 г., 19:21:21 UTC+4 пользователь Tux Leonard написал:

tvv...@gmail.com

unread,
Oct 4, 2013, 1:00:51 PM10/4/13
to beagl...@googlegroups.com
"Tool Settings" > "GCC C++ Linker" > "Libraries" > "Libraries (-l)" > "Add ..."  rt.
Problem fixed. Thanks for all.

goodz...@gmail.com

unread,
Nov 13, 2014, 12:40:12 AM11/13/14
to beagl...@googlegroups.com
Worked, thanks Ivan!
Reply all
Reply to author
Forward
0 new messages