Undefined reference to `gettimeofday'

Topics for the Eclipse Environment
Post Reply
tigger
Posts: 5
Joined: Wed Jun 01, 2016 8:22 am

Undefined reference to `gettimeofday'

Post 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!
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: Undefined reference to `gettimeofday'

Post 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...
tigger
Posts: 5
Joined: Wed Jun 01, 2016 8:22 am

Re: Undefined reference to `gettimeofday'

Post 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.
User avatar
pbreed
Posts: 1080
Joined: Thu Apr 24, 2008 3:58 pm

Re: Undefined reference to `gettimeofday'

Post by pbreed »

gettimeofday is not supported,
the time_t functions are suported.

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