升压定时器未定义的参考错误

时间:2014-06-27 07:48:11

标签: c++ ubuntu boost

我一直在尝试从boost 1.48 docs运行一个简单的示例程序:

#include <boost/timer/timer.hpp>
#include <cmath>

int main()
{
  boost::timer::auto_cpu_timer t;

  for (long i = 0; i < 100000000; ++i)
    std::sqrt(123.456L); // burn some time

  return 0;
}

我使用的是Ubuntu 12.04系统,并使用apt-get安装了libboost-all-dev软件包。该程序无法编译。有几个未定义的引用错误:

/tmp/ccSLnBrE.o: In function `main':
cpp-timer.cpp:(.text+0x16): undefined reference to `boost::timer::auto_cpu_timer::auto_cpu_timer(short)'
cpp-timer.cpp:(.text+0x63): undefined reference to `boost::timer::auto_cpu_timer::~auto_cpu_timer()'
/tmp/ccSLnBrE.o: In function `__static_initialization_and_destruction_0(int, int)':
cpp-timer.cpp:(.text+0xaf): undefined reference to `boost::system::generic_category()'
cpp-timer.cpp:(.text+0xbb): undefined reference to `boost::system::generic_category()'
cpp-timer.cpp:(.text+0xc7): undefined reference to `boost::system::system_category()'
collect2: ld returned 1 exit status

这不是关于未定义引用错误的一般性问题。它更具体到Boost Library。因此,这个问题没有回答:What is an undefined reference/unresolved external symbol error and how do I fix it?

在关于更多similar problems的其他答案中,解决方案是使用-lboost_timer标志链接库。然而,在做同样的事情时,我得到了这个:

/usr/bin/ld: cannot find -lboost_timer

0 个答案:

没有答案