C++ Boost
How to Test C++ Boost Installation
4Once C++ Boost is installed on a machine, the fastest way to test the installation is to use some of the libraries from it in test C++ programs and try to build them. The following two programs can be used for this purpose:
first.cpp
[cpp]#include
#include
int main()
{
boost::any a(5);
a = 7.67;
std::cout<
Build this program using:
The second example needs to be linked to a library file. If the above two programs build and run with out any problems, then boost is installed and working properly on your system.
second.cpp
[cpp]#include
#include
namespace bfs=boost::filesystem;
int main()
{
bfs::path p(“second.cpp”);
if(bfs::exists(p))
std::cout<
Installing C++ Boost on Gentoo and Debian/Ubuntu
11Note: Updated the post to note the availability of C++ Boost 1.34.1 libraries for Gentoo and (especially) for Ubuntu 7.10(Gutsy Gibbon).
1. C++ Boost on Gentoo:
On the shell prompt, type:
This should install the latest version of boost available for Gentoo. Currently 1.33.1 version of Boost Libraries is available for Gentoo. Synchronise(‘emerge –sync’) with the Gentoo portage if your ‘emerge -p boost’ shows an earlier version. You can install the latest version Boost 1.34.1 by adding the line “dev-libs/boost ~x86″ to “/etc/portage/package.keywords” file.
2. C++ Boost on Debian/Ubuntu:
- Update2:
Boost 1.34.1 version is now available. To install the latest version, run the following command(or select these packages from Synaptic Package Manager):sh# apt-get install libboost-date-time-dev libboost-date-time1.34.1 libboost-dev libboost-doc libboost-filesystem-dev libboost-filesystem1.34.1 libboost-graph-dev libboost-graph1.34.1 libboost-iostreams-dev libboost-iostreams1.34.1 libboost-program-options-dev libboost-program-options1.34.1 libboost-python-dev libboost-python1.34.1 libboost-regex-dev libboost-regex1.34.1 libboost-signals-dev libboost-signals1.34.1 libboost-test-dev libboost-test1.34.1 libboost-thread-dev libboost-thread1.34.1Or,
sh# apt-get install libboost.*-dev libboost-doc libboost.*1.34.1 Update1:See the new update above
Boost 1.33.1 version is now available. To install this version, run the following command(or select these packages from Synaptic Package Manager):sh# apt-get install libboost-date-time-dev libboost-date-time1.33.1 libboost-dev libboost-doc libboost-filesystem-dev libboost-filesystem1.33.1 libboost-graph-dev libboost-graph1.33.1 libboost-iostreams-dev libboost-iostreams1.33.1 libboost-program-options-dev libboost-program-options1.33.1 libboost-python-dev libboost-python1.33.1 libboost-regex-dev libboost-regex1.33.1 libboost-signals-dev libboost-signals1.33.1 libboost-test-dev libboost-test1.33.1 libboost-thread-dev libboost-thread1.33.1Or,
sh# apt-get install libboost.*-dev libboost-doc libboost.*1.33.1Run the following command(or select these packages from Synaptic Package Manager):See the update abovesh# apt-get install libboost-date-time-dev libboost-date-time1.33.0 libboost-dev libboost-doc libboost-filesystem-dev libboost-filesystem1.33.0 libboost-graph-dev libboost-graph1.33.0 libboost-iostreams-dev libboost-iostreams1.33.0 libboost-program-options-dev libboost-program-options1.33.0 libboost-python-dev libboost-python1.33.0 libboost-regex-dev libboost-regex1.33.0 libboost-signals-dev libboost-signals1.33.0 libboost-test-dev libboost-test1.33.0 libboost-thread-dev libboost-thread1.33.0You can use the following simple command to install every library present in Boost that matches the pattern, if you don’t want to be selective about which libraries to install:
sh# apt-get install libboost.*-dev libboost-doc libboost.*1.33.0
All this mess could be avoided if only Debian/Ubuntu packages could build a meta-package to include all the C++ Boost libraries. One could use the pattern libboost.* but it includes the Boost debug files(libboost-dbg) too.
3. Build C++ Programs Using Boost Libraries
Once the boost package is installed, the C++ programs that make use of boost libraries can be built simply like this:
If the program needs to be linked to a library(for eg: filesystem library), then specify the name of the library using the -l switch:
I will follow this up with the installation procedure for Slackware and RPM based distributions(Done).
Update:Thanks to Jun Zhang for pointing out the missing packages in the Boost installation command for Ubuntu; the command is now updated.
Setting the Stage for C++ Boost
1C++ is a modern language. There is a difference between calling a programming language to be “still applicable” and calling it to be “modern”. “still applicable” languages exist because they are efficient enough to solve the problems for which they were originally created and that such problems still exist. Modern languages, on the contrary, solve the problems of today, and solve them efficiently. For a language that was created in 1970s, when today’s problems were unimaginable, C++ grew with the time, gone through constant modifications so that it can better reflect the requirements of every age. One excellent proof of the constant improvements that C++ language has undergone to remain competent enough to meet the new challenges is the C++ Standard Library.
To see the tremendous improvement in the productivity levels obtained by using the higher-level utilities of C++ standard library, consider the following examples: the first one reads a set of names from the standard input, sorts them in the alphabetical order, and then prints them out to the standard output:
[cpp]vector
string name;
while(cin<
sort(names.begin(), names.end());
copy(names.begin(), names.end(), ostream_insterter(cout, "\n"));[/cpp]
Lines 2, 3, and 4 can be further simplified, but I wanted them to be that way. Consider another example, which checks whether a string is a palendrome or not:
[cpp]
compare(pal.begin(), pal.end(), pal.rbegin());
[/cpp]
No, there isn’t anything missing out there. That’s all the code that you need to check for a palendrome. Try writing these two samples without using the C++ standard library, and you will see the difference. Its not just a time-consuming effort to write them in C-style of programming but it also needs more investments in terms of testing and the maintenance jobs. Still a large number of C++ programmers do not make sufficient use of it. But those who do, look at C++ language from a completely different perspective – as a modern and a highly productive software development tool. Like, there hardly would be any memory management chores to do by the programmer, except when creating the low-level libraries.
When one gets used to this style of software development with C++ – making use of its standard library – one starts to wish for more such utilities that could solve their everyday problems equally effectively. Changes to the C++ language/standard library are not made very frequently in order to provide a level of stability to the it. The void thus created has been partially addressed by another excellent collection of quality libraries, called C++ Boost Libraries. Its not an official part of the C++ language, but its portable, efficient, rich in functionality and is very close to the philosphy of standard C++ library. Infact, many of the new additions proposed for the next version of C++ standard library are picked from the Boost libraries. A large number of C++ programmers have already started to make use of these libraries, making it unofficially official part of the C++ language
Some example libraries present in Boost are: filesystem access library, thread libarary, network socket library, regular expression library, lambda template library etc. There is a large set of collections, algorithms and iterators too. Look at the complete list of libraries if you are interested: there is a list according to the categories of the libraries and an alphabetical list.I will soon follow this up with a few examples using some of these C++ Boost libraries.
Recent Comments