Thursday, February 23, 2012

How to install Boost C++ libraries in Ubuntu and use them in Eclipse CDT

Boost is one of the most popular C++ development libraries. If you want to use them in your C++ project in Eclipse CDT in an Ubuntu environment, follow these instructions:

Installing the package
In the last Ubuntu releases, boost libraries have been split in different packages. The fastest option is to install the whole library:
$ sudo apt-get install libboost-dev
Adding the library in Eclipse CDT
Right click into your C++ project, select "Properties". Go to "C/C++ Build" options and here select "Settings". In the "GCC C++ Compiler" subsection, select "Includes" and add in the "Includes files (-include)" field, try to include any of the Boost C++ headers.
In our case we wanted to use the random numbers libraries, so we included the header file: "/usr/include/boost/random.hpp". After having done this, click on Apply.
You'll probably need to "Clean" your project before everything compiles again.

Once you've finished the settings, try to include any of the Boost sub-libraries, for example creating a new C++ class and including the following lines:
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_01.hpp>
If there is no problem at compiling nor linking, Boost C++ libraries are ready to be used in your machine.

Update
These setting instructions are fine for Eclipse Indigo.
For Eclipse Helios, though, one of the steps is different:
- To include the Boost C++ header you need to go to "GCC C Compiler" subsection instead of "GCC C++ Compiler" .

No comments:

Post a Comment