snore icon indicating copy to clipboard operation
snore copied to clipboard

Does not compile on OS X

Open hurshjain opened this issue 3 years ago • 4 comments

While compiling on OS X (Darwin Kernel Version 15.6.0, RELEASE_X86_64 x86_64), I get the following error:

snore.c:110:16: error: use of undeclared identifier 'CLOCK_REALTIME' clock_gettime(CLOCK_REALTIME, &start);

hurshjain avatar Dec 07 '21 18:12 hurshjain

Apparently, the issue is: https://github.com/pjreddie/darknet/pull/62/files/63268da2f12fca7150a3a29e3c1e990421029283

Here is a quick and dirty patch

#ifdef MACH #include <mach/clock.h> #include <mach/mach.h> #endif

#ifdef MACH // OS X does not have clock_gettime, use clock_get_time clock_serv_t cclock; mach_timespec_t mts; host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); clock_get_time(cclock, &mts); mach_port_deallocate(mach_task_self(), cclock); start.tv_sec = mts.tv_sec; start.tv_nsec = mts.tv_nsec; #else clock_gettime(CLOCK_REALTIME, start); #endif

#ifdef MACH // OS X does not have clock_gettime, use clock_get_time clock_serv_t cclock; mach_timespec_t mts; host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); clock_get_time(cclock, &mts); mach_port_deallocate(mach_task_self(), cclock); current.tv_sec = mts.tv_sec; current.tv_nsec = mts.tv_nsec; #else clock_gettime(CLOCK_REALTIME, &current); #endif

hurshjain avatar Dec 07 '21 18:12 hurshjain

Hi @hurshjain,

thanks for your feedback. Can you please check it out 284e5aa56e775803d24879954136401a106aa063 and see if it fixes the issue?

bitsmanent avatar Dec 11 '21 12:12 bitsmanent

Hi - thanks for the update. That does not fix the issue since the problem is that OS X does not have a clock_gettime function at all (regardless of C standard level). You have to use the #ifdef MACH and host_get_clock_service/clock_get_time functions intead (not the underscore between get and time in the OS X version).

I was able to compile and run successfully adding the above includes/IFDEF's on my OS X box..

hurshjain avatar Dec 11 '21 18:12 hurshjain

Ok, I had a few warnings on macOS which was indeed fixed by 284e5aa. I have no OS X at hands, feel free to send a PR otherwise I will check it out when possible.

bitsmanent avatar Dec 11 '21 18:12 bitsmanent