【问题标题】:getting started with boost cpu_timer, error: ‘boost::timer::cpu_timer’ has not been declared开始使用 boost cpu_timer,错误:'boost::timer::cpu_timer' 尚未声明
【发布时间】:2012-03-18 02:53:46
【问题描述】:

我正在尝试编译这个简单的程序来开始学习如何使用计时器:

#include <boost/timer.hpp>

using boost::timer::cpu_timer;
//...
nanosecond_type last_checkpoint_time = 0;
cpu_timer checkpoint_timer;  // start the timer

for (;;)
{
  //process_a_transaction();
  if (checkpoint_timer.elapsed().user - last_checkpoint_time > 5*1000000000LL)
  {
    //... create a checkpoint ...
    last_checkpoint_time = checkpoint_timer.elapsed().user;  
    cout << checkpoint_timer.elapsed().user << endl;
  }
}

我正在使用 gentoo linux 并发出以下命令进行编译:

g++ -I /usr/include/boost-1_46 timer1.cpp -o timer

我收到以下错误:

timer1.cpp:3:21: error: ‘boost::timer::cpu_timer’ has not been declared
timer1.cpp:5:1: error: ‘nanosecond_type’ does not name a type
timer1.cpp:6:1: error: ‘cpu_timer’ does not name a type
timer1.cpp:8:1: error: expected unqualified-id before ‘for’
timer1.cpp:8:8: error: expected unqualified-id before ‘)’ token

我正在阅读errors and warnings 下的文档,但我遇到的问题是我只有两个库:

/usr/lib/libboost_test_exec_monitor-1_46.a
/usr/lib/libboost_test_exec_monitor-mt-1_46.a

这是因为我在编译 boost 期间没有使用 static-libs 标志吗?使用静态库会更好吗?也许这是一个切线。还有什么可能导致上面给出的错误?请原谅我的无知,因为我对 C++/boost 还很陌生。

谢谢

【问题讨论】:

    标签: c++ boost gentoo


    【解决方案1】:

    我自己没有使用过cpu_timer,但快速的谷歌搜索似乎表明您应该使用&lt;boost/timer/timer.hpp&gt;。至于nanosecond_type 的错误,你需要使用另一个using 语句。

    【讨论】:

    • 感谢您的快速回复。我实际上是从那个包含语句开始的,但是我收到了这个错误: timer1.cpp:1:33: fatal error: boost/timer/timer.hpp: No such file or directory, 所以我找到了 timer.hpp 所在的位置和它位于:/usr/include/boost-1_46/boost/timer.hpp,所以当我将包含行更改为原始帖子中提供的行时。这清除了没有这样的文件或目录的问题。所以我不认为是这样。
    【解决方案2】:

    我想我弄清楚了问题所在。我在 1.49 版文档的原始帖子中引用了一个示例。 cpu_timer 在 1.48 版的 boost 文档中首次讨论。 gentoo 上的稳定版本目前是 1.46,测试只提供 1.47 版本,1.48 版本是硬屏蔽的。所以我唯一的选择是从我的系统中删除 boost 下载 1.49 的 tar 并可能破坏我的系统 wrt boost 或等待从 1.48 版本中删除硬掩码。

    【讨论】:

      【解决方案3】:

      无论如何,静态库肯定是无关紧要的,因为这是编译器错误,而不是链接器错误。在链接器阶段之前它不会查看库,直到那时只有标头是相关的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-09-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多