Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not compile on OS X #16

Open
hurshjain opened this issue Dec 7, 2021 · 4 comments
Open

Does not compile on OS X #16

hurshjain opened this issue Dec 7, 2021 · 4 comments

Comments

@hurshjain
Copy link

hurshjain commented Dec 7, 2021

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
Copy link
Author

hurshjain commented Dec 7, 2021

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

@bitsmanent
Copy link
Owner

Hi @hurshjain,

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

@hurshjain
Copy link
Author

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..

@bitsmanent
Copy link
Owner

bitsmanent commented Dec 11, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants