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

查看:99
本文介绍了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天全站免登陆