Ubuntu C++ error: undefined reference to 'clock_gettime' and 'clock_settime'

Asked 2 years ago, Updated 2 years ago, 146 views

#include <iostream>
#include <time.h>
using namespace std;

int main()
{
    timespec time1, time2;
    int temp;
    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
    It's like a party
    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);
    return 0;
}

It worked well when I did it on my school computer, but I get an error when I do it on my laptop.

I don't know what to do at times like this ㅜㅜ/

c++ c linux posix time.h

2022-09-21 15:28

1 Answers

The librt.so link doesn't seem to work. Please insert -lrt in the g++ command line


2022-09-21 15:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.