我正在尝试编译这个简单的程序,以开始学习如何使用计时器:
#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,并发出以下命令进行编译:
包含计时器/usr/ g++ /boost-1_46 -I 1.cpp -o计时器
我得到以下错误:
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还很陌生。
谢谢
发布于 2012-03-18 23:19:14
我想我知道问题出在哪里了。我在我最初的帖子中引用了1.49版文档中的一个例子。在1.48版本的boost文档中首次讨论了cpu_timer。gentoo上的稳定版本目前是1.46,测试只提供1.47版,1.48版是硬屏蔽的。因此,我唯一的选择是从我的系统中删除boost,下载1.49的tar,并可能破坏我的系统wrt boost,或者等待1.48版本中的硬掩码被删除。
发布于 2012-03-18 11:03:27
我自己并没有使用过cpu_timer,但在谷歌上快速搜索一下似乎表明你应该使用<boost/timer/timer.hpp>。至于nanosecond_type的错误,你需要使用另一条using语句来解决。
发布于 2012-03-18 17:59:35
在任何情况下,static-libs肯定是无关紧要的,因为这是一个编译器错误,而不是一个链接器错误。直到链接器阶段,它才会查看库,在此之前,只有头文件是相关的。
https://stackoverflow.com/questions/9755623
复制相似问题