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.
Related Posts:
[...] You can now test the boost installation by compiling the two programs I had mentioned in my earlier post, using the following commands: [...]
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!
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 ...").
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
Comment by John Burgoon — March 15, 2009 @ 8:58 pm