Fehler beim Linken lib?



  • Hallo

    Ich schreibe gerade mit Codeblocks und den gcc Compiler ein Tool und stoße bei folgender Methode auf folgende Fehler:

    const double get_t(void)
    {
        struct  timespec t;
        clock_gettime(CLOCK_REALTIME, &t);
    
        return(t.tv_sec + t.tv_nsec * 1000000000);
    }
    
    /home/chojo/Programmierung/sort_algo/main.c||In function ‘get_t’:|
    /home/chojo/Programmierung/sort_algo/main.c|9|error: storage size of ‘t’ isn’t known|
    /home/chojo/Programmierung/sort_algo/main.c|10|warning: implicit declaration of function ‘clock_gettime’|
    /home/chojo/Programmierung/sort_algo/main.c|10|error: ‘CLOCK_REALTIME’ undeclared (first use in this function)|
    /home/chojo/Programmierung/sort_algo/main.c|10|error: (Each undeclared identifier is reported only once|
    /home/chojo/Programmierung/sort_algo/main.c|10|error: for each function it appears in.)|
    /home/chojo/Programmierung/sort_algo/main.c|9|warning: unused variable ‘t’|
    ||=== Build finished: 4 errors, 2 warnings ===|
    

    Ich habe zu dem Problem gegoogelt und bin auf folgendes Gestoßen:

    Add -lrt to the list of libraries you link to
    

    Leider hat dies nichts an der Fehlerausgabe geändert...



  • Sieht so aus, als hättest Du <time.h> bzw. <ctime> nicht #includet.



  • doch, #include <time.h> ist drinne 🙂



  • chojo schrieb:

    doch, #include <time.h> ist drinne 🙂

    In der main.c? Kann ich mir nicht vorstellen, sonst würde die Fehlermeldung anders aussehen. Zeig ggf. mal Code.



  • Probier mal das am Anfang der main.c zu definieren:

    #define _POSIX_C_SOURCE 199309L
    

Anmelden zum Antworten