gpt4 book ai didi

C++ 错误 : undefined reference to 'clock_gettime' and 'clock_settime'

转载 作者:IT老高 更新时间:2023-10-28 11:30:38 27 4
gpt4 key购买 nike

我对 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++ 错误 : undefined reference to 'clock_gettime' and 'clock_settime' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2418157/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com