0

I have been trying to run a simple example program from 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;
}

I'm on a Ubuntu 12.04 system and I installed the libboost-all-dev package using apt-get. The program doesn't compile. There are several undefined reference errors:

/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

This is not a generic question about undefined reference errors. It is more specific to the Boost Library. Therefore it isn't answered by this question: What is an undefined reference/unresolved external symbol error and how do I fix it?

In other answers regarding more similar problems the solution was to link the libraries using a -lboost_timer flag. However on doing the same I get this:

/usr/bin/ld: cannot find -lboost_timer
Community
  • 1
  • 1
Chaitanya Nettem
  • 1,209
  • 2
  • 23
  • 45

0 Answers0