Monday, March 31, 2008

Building Boost 1.35.0

Seems I always have troubles building Boost.

To start I followed the big 'Get Boost' button on the right side of boost.org; thinking, 'That sure is obvious'. That link takes you to a download page with boost version 1.35.0 right at the top. It shows the new libs with 'Detail' and 'Download'. I took a few seconds to read the new libs section and clicked on download. This took me to sourceforge.net where they have the source code only release. Well, I knew that Boost Consulting has maintained an installer for Windows assuming you are using boost with Visual Studio. So I jumped over to their boost installer site, only to find that they don't have one yet for 1.35.0.

No problem, I'll just go back and grab the source code from sourceforge.net and follow the instructions in the getting started document. I kicked off the download and started looking for the getting started document. After a while, I figure I must be crazy, because I can't find it. I finally do a google search in order to find it. Still thinking I must have just missed it, I went back and followed every link on the right of the the main boost site. It is not under 'Introduction' or any other of the sections. I finally did locate it, it is on the main page on the left under 'GETTING STARTED'. Funny how you can look right past something like that.

So now I figure all I have to do is follow the getting started guide to build boost.

Step 1. Get Boost. I already did that. My download had already completed from sourceforge.net. I unziped it (actually un-7zed it) to c:\boost\boost_1_35_0\.

Step 2. Explain Boost Distribution. Ok, nothing new here.

Step 3. Header only libs. Right, header only libs are nice. Just compile and go. However, Boost.Thread among others need to be compiled.

Step 4. Build with a header only lib. Been there done that many times. There are sub-steps for building with Visual Studio. I always use MPC, so this is not useful to me. I plan to create a separate post or two about building boost applications with MPC. When you see how easy it is to use MPC with Boost, I doubt that you will use anything else.

Step 5. Building Boost libraries. Alright, here we go.

Step 5.1. Install Boost libraries. Yeah, thats what I wanted to do to start with. However, Boost Consulting has not yet put out an installer for 1.35.0.

Step 5.2. Build from source.

Step 5.2.1. Get bjam. I put the executable in c:\boost\boost_1_35_0\.

Step 5.2.2. Identify toolset. I want: msvc.

Step 5.2.3. Select a build directory. It says this is not necessary.

Step 5.2.4. Invoke bjam. This is where I got in trouble. I tried various combinations of commands/arguments to bjam. I must have tried to build 3-4 times. Finally I settled on the following after looking at bjam --help.
cd c:\boost\boost_1_35_0
bjam --build-type=complete --prefix="c:\boost\boost_1_35_0" install
Seems like I should have included --toolset=msvc, but I forgot and it picked msvc-8.0 anyway.

This worked for me creating a c:\boost\boost_1_35_0\lib directory as the rest of the getting started document assumes. Actually the getting started doc has it under C:\Program Files\boost\boost_1_35_0\lib, but I like c:\boost\boost_1_35_0\lib better.

After the build you can delete the c:\boost\boost_1_35_0\bin.v2 directory to free up space.

Friday, March 21, 2008

Windows XP Daylight Savings Time Problem

On March 11, 2008 I had to turn off Windows XP automatic synchronization with an internet time server because the time was wrong on my laptop. I manually set the time and forgot about it. Yesterday I realized that my email message times were off by one hour. I looked at one of my sent emails and it had "Date: Fri, 21 Mar 2008 14:39:48 -0600". I googled and figured out that since I'm in CDT this should be -0500. As a matter of fact emails sent to me from those I work with did in fact have this in the message header: "Fri, 21 Mar 2008 14:34:36 -0500 (CDT)". I couldn't figure out why my machine wasn't updated for the new daylight savings time begin date. I have all the latest Windows XP updates.

I talked to our system admin at OCI and he said I needed to apply this update:928388. I downloaded it, but it said that it was already applied. After digging around some more I found the following "How to configure daylight saving time for Microsoft Windows operating systems". I followed the steps which require you to create and apply a registry file and create and run a vbs script. That fixed the problem.

Monday, March 10, 2008

std::for_each with C-style arrays

Although std::for_each is most often used with the standard containers, it can also be used with C-style arrays. Take for example the following:
#include <algorithm>
#include <functional>
// ...
WriterTask writer[NumThreads];
std::for_each(writer, writer+NumThreads,
std::mem_fun_ref(&WriterTask::activate));
// ...
std::for_each(writer, writer+NumThreads,
std::mem_fun_ref(&WriterTask::join));
Or if you prefer:
std::for_each(&writer[0], &writer[NumThreads],
std::mem_fun_ref(&WriterTask::activate));
Compare the above with the explicit for loop:
for (int i = 0; i < NumThreads; ++i) {
writer[i].activate();
}
I'm not completely convinced that the std::for_each case is more readable. However, I liked it better than the for loop for some test cases I was writing. It collapsed a number of subsequent for loops down into one line statements making it clearer the intent of the test.