Featured Post

Customer focus is a data imperative

Age of information is really the age of confirmation and it is upon us. Gone are the days of naive customer focus termed as providing the b...

Wednesday, November 17, 2010

Building and Including Boost libraries (VS 2010)

Before I venture into the pair trading further, I had to do a modification. Which is to read all the files in a directory and calculate stats on each pair one by one. I needed a directory iterator, which took me to boost filesystem, which happens to be one of the boost libs that need to be built in order to be used. Building and using boost with VS 2010 was easier than I thought. Here are the simple steps to build boost library and linking to it.
Assuming we have the boost downloaded for windows (boost_1_45_0_beta1.zip includes bjam, so no need for separate download)

1. start a command window.
2. change to directory Program Files (x86)\VS2010\VC\bin and run "vcvars32.bat". This will setup nmake and other environment variables for visual C++ to run from command line.
3. Change to directory where boost is installed. Run "bootstrap.bat". This will get the bjam specific setup done.
4. Run the command "bjam --build-type=complete". The only reason I will build the complete libraries is if, somehow you decided to static linking instead of dynamic linking you will need to rebuild those specific libraries. The default "bjam" command will only build dynamic linking libraries.
5. After a patience, patience and more patience messages the libs will be ready and at the end you can see the directories for include and link libraries.

If you do a simple program like directory iteration (just pluck a sample from the boost_1_45_0_beta1\libs\filesystem\v3\test\msvc10 directory).

Two more steps are needed to compile and link the program.
First in the C/C++ properties add the boost directory in the "Additional Include Directories" (For me it was D:\boost_1_45_0_beta1\)

Secondly in the Linker options add the library path (in my case it was D:\boost_1_45_0_beta1\stage\lib ).

The program should compile and link. I used static linking (in the C/C++ code generation-->Runtime library options, choose the options with(/MTd) or (/MT) depending upong debug or release build) to avoid the hassle of packing my libs along with my exe, so I needed the libboost_filesystem-vc100-mt-sgd-1_45.lib. One can choose which libs to build, but in the age of terabyte hard drives, building a Gig worth of libs in one shot was the option for me.