C ++错误:对"clock_gettime"和"clock_settime"的未定义引用 [英] C++ error: undefined reference to 'clock_gettime' and 'clock_settime'

查看:691
本文介绍了C ++错误:对"clock_gettime"和"clock_settime"的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Ubuntu相当陌生,但似乎无法使它正常工作.它可以在我的学校计算机上正常工作,我不知道自己在做什么.我已经检查了 usr/include ,并且time.h很好.这是代码:

I am pretty new to Ubuntu, but I can't seem to get this to work. It works fine on my school computers and I don't know what I am not doing. I have checked usr/include and time.h is there just fine. Here is the code:

#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来进行构建和运行.任何帮助都会很棒,谢谢.

I am using CodeBlocks as my IDE to build and run as well. Any help would be great, thank you.

推荐答案

-lrt添加到g ++命令行的末尾.这会链接到librt.so实时"共享库中.

Add -lrt to the end of g++ command line. This links in the librt.so "Real Time" shared library.

这篇关于C ++错误:对"clock_gettime"和"clock_settime"的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆