Boost logo

Boost Users :

Subject: [Boost-users] Workaround for g++ problem compiling Boost.Asio examples on Ubuntu 8.04.3
From: David Featherstone (dfeathers_at_[hidden])
Date: 2009-12-09 22:35:13


I'm running Ubuntu 8.04.3 as a VMware virtual machine hosted by Windows XP on
a Lenovo T61 laptop.

Synaptic Package Manager [or apt-get] on Ubuntu 8.04.3 offers both the
libboost-dev v1.34.1 and the libasio-dev v0.3.8 packages with pre-built
libraries. Version 1.34 of Boost does not have an integrated asio library;
asio integration appears in v1.35 and later versions of Boost.

Source code for the problematic example program can be found here:
http://www.boost.org/doc/libs/1_41_0/doc/html/boost_asio/tutorial/tuttimer4/src.html
Source listing for Timer.4

The first compile problem occurs at the second #include:

  #include <boost/asio.hpp>

The compiler cannot find this header because asio.hpp was installed under
/usr/include rather than under /usr/include/boost. I fixed this issue by
creating a soft link to /usr/include/asio.hpp in /usr/include/boost:

  $ sudo ln -s ../asio.hpp /usr/include/boost/asio.hpp

Solving the second compile problem proved more difficult. The second compile
problem occurred at the first use of the boost::asio namespace:

  printer(boost::asio::io_service& io)

Changing all occurrences of 'boost::asio' to simply 'asio' solves this
problem, but makes tedium of playing with the examples and developing new
code that will be compatible with v1.35+ of Boost. Instead, I employed
namespace declarations to (artificially) nest the asio namespace within the
boost namespace. This artificial nesting is straight-forward - a single line
of code:

  #include <iostream>
  #include <boost/asio.hpp>
  #include <boost/bind.hpp>
  #include <boost/date_time/posix_time/posix_time.hpp>

   namespace boost { namespace asio { using namespace ::asio; } }

  class printer
  {
  public:
    printer(boost::asio::io_service& io)
    o o o

Caution: I have not made exhaustive tests of this workaround, but it does
compile [g++ 4.2.4] , link, and run on my platform:

  $ g++ -o timer timer.cpp -lboost_thread
  $ ./timer
  0
  1
  2
  3
  4
  Final count is 5

You may find more helpful information here, from the developer of the asio
library:
http://blog.think-async.com/ http://blog.think-async.com

-- 
View this message in context: http://old.nabble.com/Workaround-for-g%2B%2B-problem-compiling-Boost.Asio-examples-on-Ubuntu-8.04.3-tp26721653p26721653.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net