Ubuntu Linux C ++错误:未定义引用“clock_gettime”和“clock_settime” [英] Ubuntu Linux C++ error: undefined reference to 'clock_gettime' and 'clock_settime'
本文介绍了Ubuntu Linux 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.
这篇关于Ubuntu Linux C ++错误:未定义引用“clock_gettime”和“clock_settime”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文