Page 1 of 1

Undefined reference to `gettimeofday'

Posted: Wed Jun 01, 2016 8:39 am
by tigger
Hello masters,

This is my first time to use Netburner MOD5270.
Whenever I tried to compile the code, I get "undefined reference to 'gettimeofday'" message.
I think I spent enough time to figure out 'gettimeofday' problem. I seriously need a help!!

Here's my code:

Code: Select all

#include "predef.h"
#include <stdio.h>
#include <startnet.h>
#include <autoupdate.h>
#include <dhcpclient.h>
#include <sys/time.h>

extern "C" {
	void UserMain(void * pd);
	//int gettimeofday(struct timeval *t, struct timezone *tz);
}

void UserMain(void * pd)
{
	InitializeStack();
	if (EthernetIP == 0) GetDHCPAddress();
	OSChangePrio(MAIN_PRIO);
	EnableAutoUpdate();

	timeval now;

	while (1) {
		gettimeofday(&now, 0);
		iprintf("%ld.%06ld\n", now.tv_sec, now.tv_usec);
		OSTimeDly(10);
	}
}

If I remove the comment in extern "C" {...}, I get the following message:
..\main.cpp:10: error: declaration of C function 'int gettimeofday(timeval*, timezone*)' conflicts with
C:\nburn/gcc-m68k/m68k-elf/include/sys/time.h:73: error: previous declaration 'int gettimeofday(timeval*, void*)' here


I saw some related posts, but no one solved this matter.
Please help me out. Thanks!

Re: Undefined reference to `gettimeofday'

Posted: Wed Jun 01, 2016 8:59 am
by pbreed
To start with the NetBurner does not know what time it is unless you use NTP or you tell it what time it is....


I'd recommend looking a the example nburn\examples\standardstack\NTPclient


If you need usec sort of timing resolution then use the HiResTimers class....

Are you trying to measure time ?
Or Now the time of day?

The Natural RTOS time counts are Secs and TimeTicks.... both automatically maintained at the TimeTick resolution...

Re: Undefined reference to `gettimeofday'

Posted: Wed Jun 01, 2016 9:31 am
by tigger
Hello pbreed,

Yes, I need to use usec for my project.
Thanks for your suggestion.

The reason for my post is that since nobody solved this 'gettiemofday' matter, I just want someone to provide the solution not other suggestion/links. In this forum, I think it's good to know the solution for those of people who are having same concern with me. If you know, please provide the solution.

Re: Undefined reference to `gettimeofday'

Posted: Wed Jun 01, 2016 9:43 am
by pbreed
gettimeofday is not supported,
the time_t functions are suported.

It should have been removed from the header file...