clock_gettime Funktion wird nicht gefunden
-
Hi,
ich bin gerade am verzweifeln, denn ich schaffe es nicht, dass der compiler die clock_gettime Funktion findet und übersetzt.
Hier ist der Code:#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <time.h> #define BILLION 1000000000L; extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __THROW; int main(void) { struct timespec start, stop; double accum; if( clock_gettime( CLOCK_MONOTONIC , &start) == -1 ) { perror( "clock gettime" ); return EXIT_FAILURE; } if( clock_gettime( CLOCK_MONOTONIC , &stop) == -1 ) { perror( "clock gettime" ); return EXIT_FAILURE; } accum = ( stop.tv_sec - start.tv_sec ) + (double)( stop.tv_nsec - start.tv_nsec ) / (double)BILLION; printf( "%lf\n", accum ); return EXIT_SUCCESS; }
Ich bekomme folgende Meldung:
**** Build of configuration Debug for project TEST **** make all Building file: ../src/main.c Invoking: GCC C Compiler gcc -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/main.d" -MT"src/main.d" -o"src/main.o" "../src/main.c" Finished building: ../src/main.c Building target: TEST Invoking: GCC C Linker gcc -o"TEST" ./src/main.o ./src/main.o: In function `main': /home/anna/Eclipse/workspace/TEST/../src/main.c:19: undefined reference to `clock_gettime' /home/anna/Eclipse/workspace/TEST/Debug/../src/main.c:21: undefined reference to `clock_gettime' /home/anna/Eclipse/workspace/TEST/Debug/../src/main.c:28: undefined reference to `clock_gettime' collect2: ld gab 1 als Ende-Status zurück make: *** [TEST] Fehler 1
Ich benutze Ubuntu 8.10 und Eclipse.
Wo ist denn der Fehler??
-
Schau in der manpage man: clock_gettime. Da steht bei mir (Ubuntu 9.04) "Link with -lrt."
also:
gcc -o"TEST" ./src/main.o -lrt
-
aaaaah, jetzt funzt es,
danke schöön!