Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C++ compile error

Options
  • 24-01-2008 12:13pm
    #1
    Registered Users Posts: 357 ✭✭


    Trying to compile this code on ubuntu with g++. Getting these errors.

    utime.cpp: In function ‘int main(int, char**)’:
    utime.cpp:27: error: ‘exit’ was not declared in this scope
    utime.cpp:35: error: ‘atoi’ was not declared in this scope
    utime.cpp:57: error: ‘usleep’ was not declared in this scope

    Can anyone see where I might be going wrong?
    Cheers for any help.
    #include<stdio.h>
    
    #include<time.h>
    
    #include <sys/time.h>
    
    #include <sys/resource.h>
    
     
    
    int main(int argc, char** argv){
    
     
    
    struct  timeval tv;
    
    struct  timezone tz;
    
    int i,delay,num_iter;
    
     double init,start,stop;
    
    if (argc!=3) {
    
        fprintf(stderr, "Usage: %s <sleep time..usec><num_iteration>\n", argv[0]);
    
        exit(1);
    
      }
    
     
    
    //  progname=argv[0];
    
      delay=atoi(argv[1]);
    
      num_iter=atoi(argv[2]);
    
      printf("Delay is %d usec..num_iter is %d\n",delay,num_iter);
    
      gettimeofday( &tv,&tz);
    
      init=tv.tv_sec + tv.tv_usec*0.000001;
    
      for(i=0;i<num_iter;++i)
    
        {
    
          gettimeofday( &tv,&tz);
    
          start=tv.tv_sec + tv.tv_usec*0.000001;
    
         
    
          // Now sleep
    
          usleep(delay);
    
          gettimeofday( &tv,&tz);
    
          stop=tv.tv_sec + tv.tv_usec*0.000001;
    
               
    
          printf("Iteration %d..slept for %lf usec\n",i+1,(stop-start)*1000000);
    
        }
    
     
    
    printf("Total time taken : actual %lf  theory(excl. runtime): %d,   usec \n",(stop-init)*1000000,num_iter*delay);
    
    return 0;
    
    }
    


Comments

  • Registered Users Posts: 3,875 ✭✭✭ShoulderChip


    sorry, no.


  • Subscribers Posts: 4,075 ✭✭✭IRLConor


    #include <stdlib.h>
    
    ?

    When you get errors like that, look up the manpage for the missing functions (e.g. "man atoi") and it will usually tell you what you need to include at the top.


  • Registered Users Posts: 357 ✭✭apoch632


    Cheers man. I'd a feeling it was something silly like that i left out.


Advertisement