开始使用boost-cpu_timer时,错误:“boost::timer::cpu_timer”尚未声明
getting started with boost cpu_timer, error: ‘boost::timer::cpu_timer’ has not been declared
我正试图编译这个简单的程序来开始学习如何使用计时器:
#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/brust-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
我在错误和警告下阅读文档,但我遇到的问题是我只有两个库:
/usr/lib/libboost_test_exec_monitor-1_46.a
/usr/lib/libboost_test_exec_monitor-mt-1_46.a
这是因为我在编译boost时没有使用静态libs标志吗?使用静态库会更好吗?也许这是一条切线。还有什么原因会导致上述错误?请原谅我的无知,因为我对C++/boost还很陌生。
感谢
我自己还没有使用cpu_timer
,但在谷歌上快速搜索似乎表明应该包含<boost/timer/timer.hpp>
。至于nanosecond_type
的错误,您需要使用另一个using
语句。
我想我已经找到了问题所在。我在1.49版本的文档中引用了我的原始文章中的一个例子。cputimer在1.48版本的boost文档中首次进行了讨论。gentoo上的稳定版本目前是1.46,测试只提供1.47版本,1.48版本是硬屏蔽的。因此,我唯一的选择是从我的系统中删除boost下载1.49的tar,并可能破坏我的系统wrt boost或等待从1.48版本中删除硬掩码。
在任何情况下,静态库都是不相关的,因为这是编译器错误,而不是链接器错误。直到链接器阶段,它才查看库,在此之前,只有标头是相关的。
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- boost::进程间消息队列引发错误
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- cmake如何在fedora工作站中找到boost静态库包
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- Boost Graph Library,修复节点大小
- 什么是"#include <boost/functional/hash.hpp> "?
- 基于boost的程序的静态链接——zlib问题
- C++:如何在CLion IDE中安装Boost
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 如何在boost beast http请求中设置http头
- Boost Spirit,获取迭代器内部语义动作
- boost::asio::steady_timer()与sleep()我应该使用哪一个
- 是否需要在 Timer.5 boost::asio 教程中运行新线程?
- 使用boost::asio::deadline_Timer实现通用Timer类时出现问题
- 在 c# 中是否有等效的 boost::timer::cpu_timer
- 开始使用boost-cpu_timer时,错误:“boost::timer::cpu_timer”尚未声明
- 如何从boost::timer::cpu_timer获取以秒为单位的运行时间
- Boost Timer 24小时格式
- 如何重启boost::timer::cpu_timer