user09123789542 user09123789542 - 1 year ago 81
C++ Question

Using time.h on macos for cross compiler

I want to compile the following code on macos:

struct timeval tv;
int retval = gettimeofday (&tv, NULL);
if (retval == 0)
TIMEVAL_TO_TIMESPEC (&tv, tp); //here I am getting the error
return retval;

But I am getting the error

error: 'TIMEVAL_TO_TIMESPEC' was not declared in this scope


I am compiling with the cross compiler of android. I tried to include the time.h header explicitly, and it still doesn't find TIMEVAL_TO_TIMESPEC. How can I dompile this code correctly?

Answer Source

The below is the link that explains all date time concepts/standards from GNU C library, where most of the platforms stick to.

If you are targeting a cross platform development better stick to the above standards.

Like "nathan" specified in comments, the macro used is specific to some UNIX like systems.

I quickly verified the GNU C library for date and time (above link). I did not see the "TIMEVAL_TO_TIMESPEC" macro any where.

May be operating systems that descends from "Berkeley Software Distribution" may have "TIMEVAL_TO_TIMESPEC", but may not be part of GNU standard C library, as far as I know.

Correct me If I am wrong.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download