Boost libraries provide many interesting C++ libraries with cool functionalities. I've been using for many years now boost shared pointers and boost regex library (for regular expression). In particular, I'm using them in my software GNU Source-Highlight. These libraries are usually available in LInux distributions, but if they are not, and you need to build them (compile them) from sources... well... here comes trouble :-)
The first time, it is actually not easy to build boost libraries from sources, even though you're used to build programs from sources following the usual "./configure && make && make install"; in particular, boost use their own build system based on bjam. Indeed, I've had many complaints from source-highlight users when it comes to build source-highlight and the boost libraries are not available in their system.
I hope this post sheds some light for building boost libraries from source. In particular, I'll concentrate on regex library (in fact, you're not required to build all the libraries: you can simply select the ones you're interested in). Note that some boost libraries come only in the shape of header files (like shared pointers) and others require also a lib file (like regex). Note, however, that all the header files will be installed anyway (they basically do not require any compilation), while library files require compilation, and compiling all the libraries in boost may require some time; thus, having the chance to select only some libraries is quite useful.
In this post I'll assume that you want to build only the regex library and to install all the built files into $HOME/opt/boost (so that you will not need root access rights).
Once you unpacked the sources into a directory, say ~boost
tar xjvf ~/Downloads/boost_1_39_0.tar.bz2you get into that directory
cd ~boostand run the booststrap command
./bootstrap.sh \Hopefully, you will get no error, and then you're ready to build and install the boost headers and the regex library with the following command:
./bjam --build-dir=build --layout=system installThis will install the directories include and lib into $HOME/opt/boost.
You can now test your installation using the example program you find in the boost website, example.cpp:
boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" );
if (boost::regex_match(line, matches, pat))
std::cout << matches << std::endl;
Since you installed boost in a directory which is probably not in the search path of your compiler, you will need to specify the path for header inclusion and the path for library, as follows:
g++ -I$HOME/opt/boost/include example.cpp -o example \If everything went fine, you'll have your program to test.
If you want to run your program, remember that the boost regex library you built is a dynamic library, thus, again, since it is not installed in a system path where the loader searches for libraries to load at run-time, you'll need to specify that path with the environment variable LD_LIBRARY_PATH, e.g.,
LD_LIBRARY_PATH=$HOME/opt/boost/lib ./exampleAs I said before, you could have install the library and headers in system path, e.g., /usr; all you have to do is to specify a different bootstrap command
./bootstrap.sh \and then run bjam as before (but with root privileges).
Hope this helps :-)