代码之家  ›  专栏  ›  技术社区  ›  naspinski

C++错误:未定义的“CcLogyGETTIME”和“CcLyLyStTimeTimes”引用

  •  148
  • naspinski  · 技术社区  · 16 年前

    我对Ubuntu还很陌生,但我似乎无法让它工作。它在我学校的电脑上运行得很好,我不知道我在做什么。我查过了 还有时间。那里很好。代码如下:

    #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;
    }
    

    我使用代码块作为我的IDE来构建和运行。任何帮助都很好,谢谢。

    4 回复  |  直到 8 年前
        1
  •  291
  •   Mark Lakata    11 年前

    添加 -lrt 到g++命令行的末尾。此链接位于librt.so“实时”共享库中。

        2
  •  42
  •   David Guyon    12 年前

    c++ -Wall filefork.cpp -lrt -O2
    

    gcc 版本4.6.1, -lrt 之后 文件叉.cpp

    一些更老的 合同通用条款 版本不关心位置。

        3
  •  30
  •   Deleted Andrey    6 年前

    自从glibc版本2.17以来 -lrt

    这个 clock_* change history of glibc 2.17 更改发生的位置解释了更改的原因:

    +* The `clock_*' suite of functions (declared in <time.h>) is now available
    +  directly in the main C library.  Previously it was necessary to link with
    +  -lrt to use these functions.  This change has the effect that a
    +  single-threaded program that uses a function such as `clock_gettime' (and
    +  is not linked with -lrt) will no longer implicitly load the pthreads
    +  library at runtime and so will not suffer the overheads associated with
    +  multi-thread support in other code such as the C++ runtime library.
    

    如果您决定升级glibc,那么您可以检查 compatibility tracker of glibc 如果您担心使用新的glibc是否会有任何问题。

    要检查系统上安装的glibc版本,请运行以下命令:

    ldd --version
    

    (当然,如果您使用的是旧glibc(<2.17)那么你仍然需要 .)

        4
  •  27
  •   Jonathan Spooner    14 年前

    我也遇到了同样的错误。我的链接器命令确实包含rt库 -lrt 这是正确的,它已经工作了一段时间。重新安装Kubuntu后,它停止工作。

    另一个论坛帖子建议 -轻轨 需要在项目对象文件之后。 移动 到命令结束时,我解决了这个问题,虽然我不知道为什么细节。

    推荐文章