Hi, I'm new to C++ and I am writing a project in it that I want to build on both Windows CE and VxWorks, so I am compiling the project in both MS Visual Studio and Wind River Workbench.
There are a number of places in the app where I want to get the current date and time (number of seconds since 1/1/1970) but I can't figure out how to make it work! From what I can tell, time(time_t * timer) is the way to go, but while this compiles fine for VxWorks, when I compile it for Windows I get a strange linker error which says that there are unresolved externals in the function that contains the call to time().
Help! (Thanks in advance!)
Rachel

time function
Drokker
Tinomolloy
All you do is include time.h, and do something similar to the following snippet
time_t x;
time(&x);
Learning VB
That's exactly what I want to do--here is essentially what I'm doing:
#include "time.h"
void foo(void)
{
time_t curr_time;
time(&curr_time);
}
or I was wondering if this was an option:
void foo(void)
{
time_t curr_time = time(NULL);
}
Either way I get the same error:
error LNK2019: unresolved external symbol time referenced in function "protected: void __cdecl foo(void)"
It seems like it should be simple, what is going on
MarlAtkins
Damir Dobric
Also make sure the the project property Linker, Input, Ignore all default libraries is set to No.
man_in_trouble
I found the following implementation of time_t time(time_t *t) based on the time functions that do exist on CE. I haven't verified the code myself, but at a glance it looks sound enough. Just place this snippet in your code and Robert's your fathers brother.
time_t time( time_t *inTT )
{
SYSTEMTIME sysTimeStruct;
FILETIME fTime;
ULARGE_INTEGER int64time;
time_t locTT = 0;
if ( inTT == NULL ) {
inTT = &locTT;
}
GetSystemTime( &sysTimeStruct );
if ( SystemTimeToFileTime( &sysTimeStruct, &fTime ) ) {
memcpy( &int64time, &fTime, sizeof( FILETIME ) );
/* Subtract the value for 1970-01-01 00:00 (UTC) */
int64time.QuadPart -= 0x19db1ded53e8000;
/* Convert to seconds. */
int64time.QuadPart /= 10000000;
*inTT = (time_t)int64time.QuadPart;
}
return *inTT;
}
Nima_Don
DmitryMS
Jonathan Cran
sjkepner
Anyhoo, please explain why you have to include Wind River's time.h instead of MSFT's.
lou_1
Apparently, the old time functions arent implemented in the runtime library for Windows CE. You could resort to Win32 methods like GetLocalTime and GetTimeZoneInformation instead for your Visual Studio build.
Amos Soma
The property setting is as you suggested, and as for the undefined symbol, do you mean unresolved symbol All the error message says is "unresolved external symbol time...". (Is there some way to get more information about the error that you're wanting to know ) The problem is with the function call, because I can declare the time_t variables without a problem, it is only when I add the function call that I get the failure.
(Thanks for you help, I'm really tearing my hair out over this)
Shinzo-Prime
I wasn't trying to be rude at all, I was just asking--I do appreciate your help. What is MSFT The time.h I am using is the one provided for Windows Mobile, since I am using CE. So, this version is undoubtedly different from the full framework version and perhaps that is the discrepency here, as einaros notes time() is not implemented in this version. Because as I understand, this time.h provides _time64() which will not work in VxWorks and the VxWorks time.h provides time() and clock_gettime() which will not work in CE.
I will look into this Dinkumware suggestion by einaros as well.
NetPochi
As I've pointed out, the time method isn't implemented in the runtime library for Windows CE.