Tuesday, December 11, 2007

installing boost::asio

This boost C++ library is an interesting and very useful for dealing with low level sockets. As its portable, you don't have to deal with winsock or socket.h! Programming with it is fairly easy as far as I've gotten so far, and the library supports both synchronous and asynchronous operations on sockets. As of version 1.34 of boost, asio is not included in a standard install of boost, so to install some work (and trouble) is needed.

My experience with installing asio was rather difficult. Instructions are given, but they are long winded and don't contain all the steps and background needed to fully understand what is going on, so I'll attempt to explain., starting with the primary differences between the available download options.

There are two different options for downloading, one requires a distribution of boost, versions 1.33 or 1.34, and the other does not require this. There is not much difference between the two, other then a few functions won't work in the release that does not require boost. As I installed both, I'll go through both below starting with the install that does not require boost as its easier to install.

asio without boost install - Download one of the compressed files that start with asio followed by a number. I downloaded asio-0.3.9.tar.gz. Once you have the download, uncompress it into a new directory. That is it! When using it remember to #include "path/to/asio.hpp"

asio with boost install - Download one of the compressed files that start with boost_asio followed by a number. I downloaded boost_asio_0_3_9.tar.gz. Once you have the download uncompress it into a new directory. If you do not have a boost source install, you will need to download it. Pick the top option, labeled "boost". Uncompress it to a new directory and enter that directory (cd into it). You will need to move the files in the asio download into the boost source files. Do so by copying all files in boost/ and src/ to the respective files in the boost directory. Then type in ./configure (add options as you wish), make, and finally make install if you choose to install this source build to your operating system. (If there is a better way, please comment below, however the instructions on the use of bjam and boost.build were a tad on the confusing side.) When making use of this, make sure to link to the boost::system libraries.

I have heard that asio will come default with boost 1.35, however that was just in a chat on IRC in #boost and can be wildly wrong :).

I'll comment more when I explore the usage of this library and get a chance to compare it to using socket.h. If anyone reading this has better install instructions for asio with boost, I would like to hear about it, as is the instructions involve remaking all boost libs to get the needed boost::system dependency.

No comments: