其他分享
首页 > 其他分享> > C错误:对’clock_gettime’和’clock_settime’的未定义引用

C错误:对’clock_gettime’和’clock_settime’的未定义引用

作者:互联网

我对Ubuntu很新,但我似乎无法让它工作.它在我的学校电脑上工作正常,我不知道我在做什么.我检查了usr / include和time.h就好了.这是代码:

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

int main()
{
    timespec time1, time2;
    int temp;
    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1);
    //do stuff here
    clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2);
    return 0;
}

我正在使用CodeBlocks作为我的IDE来构建和运行.任何帮助都会很棒,谢谢.

解决方法:

将-lrt添加到g命令行的末尾.这链接在librt.so“实时”共享库中.

标签:c,linux,ubuntu,posix,time-h
来源: https://codeday.me/bug/20190925/1817232.html