Every Flavour Beans

“The time has come…to talk of many [technologies].” –Lewis Carroll(’The Walrus and the Carpenter’)
Development Tools. Web Frameworks. GNU/Linux. Nokia N800. Video Encoding.

March 16, 2006

How to Test C++ Boost Installation

Filed under: C++ Boost — tabrez @ 4:02 pm

Once 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

C++:
#include<iostream>
#include<boost/any.hpp>
int main()
{
    boost::any a(5);
    a = 7.67;
    std::cout<<boost::any_cast<double>(a)<<std::endl;
}

Build this program using:

sh# g++ -o first first.cpp

The second example needs to be linked to a library file.
second.cpp

C++:
#include<iostream>
#include<boost/filesystem/operations.hpp>
namespace bfs=boost::filesystem;
int main()
{
    bfs::path p("second.cpp");
    if(bfs::exists(p))
    std::cout<<p.leaf()<<std::endl;
}
sh# g++ -o second second.cpp -lboost_filesystem

If the above two programs build and run with out any problems, then boost is installed and working properly on your system.


If you want to receive future posts by email, enter your email address here:

Related Posts:

4 Comments »

[...] You can now test the boost installation by compiling the two programs I had mentioned in my earlier post, using the following commands: [...]

Quote

Pingback by Every Flavour Beans » Installing C++ Boost on SuSE and Fedora — April 28, 2006 @ 2:47 am

Thanks - the article was very helpful!

(I think comment #1 may have gotten "eaten" - perhaps it referred to the examples folders and Jamfile included with the distribution?)

Please keep up the good work!

Quote

Comment by JOanzi — December 6, 2006 @ 7:44 am

JOanzi,
Thanks.

The comment #1 is actually a pingback/trackback and is displayed only partially. The full text can be read by following the URL at the bottom("Pinkback by ...").

Quote

Comment by tabrez — December 6, 2006 @ 2:55 pm

Thanks for these excellent tutorials. May I suggest a tutorial? Walking someone _carefully_ through the Boost installation process would be marvelous. I am trying to install Boost on Mac OSX Leopard, and although I am doing the builds and getting results, I realize I am new enough to C++ that I am not confident in doing things that most tutorials assume I can do, such as linking a library, or making sure that paths are set correctly. I understand the concepts, but the actual syntax, what a program looks like, and what failure looks like are very very helpful. For example, your second example above shows linking in C++.

You might smile, but to someone who doesn't know what to ask, Googling "linking C++" only causes the overwhelming feeling of despair. Your examples have helped me tremendously, and I encourage you to write some more. The best one to add to this tutorial would be the "ELSE" part of your statement above: "IF the above two programs build and run with out any problems, then boost is installed and working properly on your system..."

Thanks again for your excellent work!
John

Quote

Comment by John Burgoon — March 15, 2009 @ 8:58 pm

RSS feed for comments on this post. TrackBack URI

Leave a comment

Subscribe without commenting


Copyright (c) 2006, 2007 Tabrez Iqbal.
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. Verbatim copying and distribution of this entire article is permitted in any medium without royalty provided this notice is preserved. A copy of the license is included in the section entitled "GNU Free Documentation License".


Powered by WordPress
This website is hosted by Dreamhost


You are viewing a mobilized version of this site...
View original page here

Mobilized by Mowser Mowser
Mobilytics