Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4025792
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:53:26+00:00 2026-05-20T10:53:26+00:00

When compiling a program I wrote on Mac OS X after installing the necessary

  • 0

When compiling a program I wrote on Mac OS X after installing the necessary libraries through MacPorts, I get this error:

In function 'nanotime':
error: 'CLOCK_REALTIME' undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)

It appears that clock_gettime is not implemented in Mac OS X. Is there an alternative means of getting the epoch time in nanoseconds? Unfortunately gettimeofday is in microseconds.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T10:53:27+00:00Added an answer on May 20, 2026 at 10:53 am

    In effect, it seems not to be implemented for macOS before Sierra 10.12. You may want to look at this blog entry. The main idea is in the following code snippet:

    #include <mach/mach_time.h>
    #define ORWL_NANO (+1.0E-9)
    #define ORWL_GIGA UINT64_C(1000000000)
    
    static double orwl_timebase = 0.0;
    static uint64_t orwl_timestart = 0;
    
    struct timespec orwl_gettime(void) {
      // be more careful in a multithreaded environement
      if (!orwl_timestart) {
        mach_timebase_info_data_t tb = { 0 };
        mach_timebase_info(&tb);
        orwl_timebase = tb.numer;
        orwl_timebase /= tb.denom;
        orwl_timestart = mach_absolute_time();
      }
      struct timespec t;
      double diff = (mach_absolute_time() - orwl_timestart) * orwl_timebase;
      t.tv_sec = diff * ORWL_NANO;
      t.tv_nsec = diff - (t.tv_sec * ORWL_GIGA);
      return t;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I am compiling a program with make but I get the error of
Recently I tried compiling program something like this with GCC: int f(int i){ if(i<0){
While compiling a program in Java I got this big WARNING warning: [unchecked] unchecked
I am getting the following error while compiling a sample program in Qt 4.5
I am a beginner, and wrote the following program for fun, to search through
I recently wrote a post: Weird Error in C++ Program: Removing Printout Breaks Program
I just started learning Free Pascal and I wrote this fairly basic program to
I wrote this header file for a another main program. This file declares a
I am compiling my program that will run on linux gcc 4.4.1 C99. I
I'm compiling a program on my 64bit machine, but I'm not sure if it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.