Thursday, November 4, 2010

Getting Boost.Regex + Unicode to work with Microsoft VC++ 2010

[ This article pertains to Boost version 1.44. It may or may not remain useful in the future, when newer Boost versions appear, depending on how Boost.Regex’s developers would arrange the build process. ]

Although the subject above may seem to be overly specific, I think many people might want to use regular expressions with international text support in their programs being developed in Windows/Microsoft environment. I’m in no way a Boost.Regex expert or even seasoned Boost user. I just would like to share my “newbie” experience with programmers who are trying to achieve the same as I did. And for the current Boost’s version - 1.44 - it is not so easy.
And one thing should be mentioned before we start. I adhere to the principle of least resistance. For the process of software library linking that means the following: use vendor-supplied compiled binaries as much as you can and use your hands as sparingly as you can. Probably the moment when you need to build a library from sources (which can be quite troublesome) or do some manual tweaking will come. Maybe, but it’s a future, so leave all hassles for that future. For now we are going to get our libraries up and running, and to do it fast. At least on Windows platform, this approach seems to be sound.

OK, let’s start. As it’s noted here, to support Unicode you have two approaches: the simple one and the good one. For some cases the simple approach can suffice however actually it is not portable and has several disadvantages. To help you build a true Unicode-aware application, Boost.Regex - one of the best regular expression libraries - requires ICU – one of the best Unicode libraries. The following describes how to get Boost.Regex and ICU work together.

First we need to obtain the latest release of ICU from here. In the download page choose ICU4C as we need to interface the ICU library with C/C++ programs. Download the Windows binaries .zip file and unpack it to some folder on your hard drive, say C:\Distr\icu.

What we need to do in order to build Boost.Regex with ICU is described in detail here. However building from scratch is still not a preferred option, and when I was looking for an alternative I came across the BoostPro Installer which can provide us with binaries for every possible Boost library, every compiler, threading model, etc. But… BoostPro does not cover per-library specifics such as ICU-enabled Regex.

Therefore we have no other choice but to compile Boost.Regex by hand. However BoostPro Installer still can be of use for us because it can serve as a convenient download tool that will provide us with Boost sources and (what is more important) some compiled Boost tools (you will be able to see below why we need them). For now run BoostPro and proceed until the wizard page appears where compilers and variants can be selected. There you should select no checkboxes at all. On the next page leave only four checkboxes checked at the top of the list. Then advance to the end of the wizard and wait for files to be downloaded and installed.

Assume you chose to install Boost to the default installation folder (C:\Program Files\boost\boost_1_44). In the C:\Program Files\boost\boost_1_44\libs\regex\build folder you will find several vc*.mak files which – what a pleasant surprise! - outnumber those mentioned in the documentation on the Boost's web site. But what is not so good surprise is that they lack one for MSVC10. Running vc9.mak by VC10’s nmake.exe gives many errors and unknown option warnings which look a bit scary. Editing makefiles manually is not an option for us as we need the result as soon as possible.

Somehow guys at BoostPro had managed to built Regex library with MSVC10 and are unlikely to conceal their secret knowledge from the public, so it has to be somewhere around. In Boost.Regex’s build folder there are also some .sh files which are Unix shell scripts, a .cpp file and a cryptic Jamfile.v2. Relating this name and the information obtained from Regex’s building guide lets us conclude that we need a program called bjam (which in fact is a part of Boost’s own build system) to run Jamfile.v2. Fortunately, as a result of installation by BoostPro, a compiled bjam.exe can be found in the C:\Program Files\boost\boost_1_44\bin folder.

Now let’s launch a command line window and change the working directory to Regex’s build folder. The straight-forward (partially borrowed from the Regex installation guide and Google search results) command
"C:\Program Files\boost\boost_1_44\bin\bjam" -sICU_PATH="C:\Distr\icu" toolset=msvc-10.0 release threading=multi link=shared

among other info outputs an undesired message

has_icu builds : no,

which indicates that the test program has_icu_test.exe could not be compiled or linked correctly and the build script falls back to compilation/linking of Regex without ICU. After struggling for a while with this strange problem I found that by some reason the build tool requests for debug versions of ICU libraries which of course I have none of and didn’t intend to use. I must confess, I’m not fond of studying new software tools that I’m sure I wouldn’t use much on but here I had no other choice. Eventually I found that ‘lib’ rule sets select wrong alternatives, even when configuration features are explicitly provided via command-line arguments, just like in the command above. E.g. this block in the Jamfile.v2 file

   lib icuuc : : <search>$(ICU_PATH)/lib <link>shared <runtime-link>shared ;
   lib icuuc : : <toolset>msvc <variant>debug <name>icuucd <search>$(ICU_PATH)/lib <link>shared <runtime-link>shared ;
   lib icuuc : : <name>this_is_an_invalid_library_name ;

chooses the second line, i.e. the icuucd library (debug version of one of ICU’s libraries) but supposed to choose the first line, i.e. icuuc library (release version of that ICU’s library). Other rule sets behave in a similar way. I had no time to investigate why this may happen and I don’t see any reasons not to follow the path of least resistance and use a no-brainer: I commented out in the Jamfile.v2 file all alternatives which may lead to selection of incorrect libraries, like this:

   lib icuuc : : <search>$(ICU_PATH)/lib <link>shared <runtime-link>shared ;
#   lib icuuc : : <toolset>msvc <variant>debug <name>icuucd <search>$(ICU_PATH)/lib <link>shared <runtime-link>shared ;
#   lib icuuc : : <name>this_is_an_invalid_library_name ;
#   lib icudt : : <search>$(ICU_PATH)/lib <name>icudata <link>shared <runtime-link>shared ;
   lib icudt : : <search>$(ICU_PATH)/lib <name>icudt <toolset>msvc <link>shared <runtime-link>shared ;
#   lib icudt : : <name>this_is_an_invalid_library_name ;
#   lib icuin : : <search>$(ICU_PATH)/lib <name>icui18n <link>shared <runtime-link>shared ;
#   lib icuin : : <toolset>msvc <variant>debug <name>icuind <search>$(ICU_PATH)/lib <link>shared <runtime-link>shared ;
   lib icuin : : <toolset>msvc <variant>release <name>icuin <search>$(ICU_PATH)/lib <link>shared <runtime-link>shared ;
#   lib icuin : : <name>this_is_an_invalid_library_name ;

Mostly this is it. Save corrections to the Jamfile.v2 file and run the above command again. This should work the right way. My configuration for bjam was release threading=multi link=shared which means: I need release (non-debug) version, I need multi-threaded, I need DLL. You might probably want another configuration, then you may change release to debug, multi to single or shared to static.

When everything is going right, at the beginning of bjam’s console output you should see a message has_icu builds : yes.

As a result of bjam’s work, all generated files will be placed into the C:\Program Files\boost\boost_1_44\bin.v2\libs\regex\build\msvc-10.0\release\threading-multi folder (the last two subfolders can vary depending on your options).

To double check, you can examine a couple of .rsp files which also would reside in the output folder. E.g. the file c_regex_traits.obj.rsp should contain the line

   -DBOOST_HAS_ICU=1

And the file boost_regex-vc100-mt-1_44.dll.rsp should contain the lines

   "icuuc.lib"                   
   "icudt.lib"
   "icuin.lib"

That’s it. For how to use ICU-powered Boost.Regex please refer here
more >>

Monday, September 27, 2010

How to clean the heatsink and renew thermal compound in a Sony Vaio VGN-Z590 (VGN-Z Series) laptop

In this post I'll describe how a Sony Vaio VGN-Z590 laptop can be disassembled in order to clean its heatsink and renew CPU or other chips' thermal grease.

Make sure you have a set of jeweler's screwdrivers, a set of flat-tip and Philips screwdrivers and sufficient amount of CPU thermal compound. Also read the text thoroughly to understand if you need anything else. 

Note that preview pictures within this post are not only scaled down but also truncated from either side by Google Picasa and my circle or box markings are not always visible so you need to click on a photo to see it full size.

Okay, let's start with it. Shut down the computer, disconnect the DC power adaptor and remove the battery. Place the unit upside down.

Remove the 7 screws right on the bottom (red) and the 2 screws in the battery compartment (green). Then unscrew the memory lid (left yellow circle) and remove it, underneath the lid there’s the last screw securing the housing, remove that screw.

Turn the laptop over and open the lid fully. There’s a series of latches (red in the picture below) and metal hooks holding the keyboard panel along the left, right and front side of the housing. Use your nails or a plastic ruler to insert it between the keyboard panel and the middle frame and gently release the keyboard panel.

[ The middle frame is the grey colored panel containing the battery, HDD and wireless LEDs on the front side of the housing. ]

After the keyboard panel has been released you can lift it up however there’s the keyboard ribbon cable still holding it. Unplug its connector from the mainboard and finally remove the keyboard.

Next you will need to remove the middle frame. Note that the middle frame is a plastic structure of variable thickness, in some points very thin. A part of the middle frame contains an aluminum bracket attached to other parts by plastic rivets. So you must be very cautious when removing the middle frame.

First unscrew the 3 black screws (green in the photo below) holding the HDD and DVD drive and one another black screw next to the bigger HDD bracket (blue). Then remove the 2 silver screws next to the speakers (encircled by red). Next disconnect the HDD and DVD drive connectors from the mainboard (yellow) by gently pulling them up.

To remove the DVD drive you need to open its door. To do this with no electrical power supplied take a needle, insert it in the small hole (marked in the photo below) and push. The door will open. Pull the DVD drive carefully out of the housing.

Next remove the HDD along with the two aluminum mounting brackets holding it (red in the photo below) and the black rubber gaskets on its corners. Note that the brackets are captured by the series of plastic latches (green) which are below the HDD level and are not visible. Therefore you need to push up gently the entire assembly while rocking it slightly. Probably you’ll need an assistance of a flat-tip screwdriver to release the latches when you figure out where they are and how they hold the assembly.

What is still holding the middle frame are the latches next to laptop lid hinges. Two of these latches are covered with the two barrel-shaped side caps (shown in the photo below): one at the DC jack side and the other at the power button side.

To remove them use a bamboo skewer or flat-tip screwdriver, tip wrapped with one layer of soft insulation tape. These will let you avoid scratches and dents when you push the caps by the inner side in the directions indicated by the arrows in the picture above. See the following photo to understand where the latches are located inside the caps.

Once you removed the barrel caps you are able to release the following 3 latches (those two which were covered by barrel caps + one more) using a screwdriver or a thin ruler:

Then unplug the three white connectors indicated in the photo below. To do this grab the wire next to the connector and pull it carefully upwards gradually applying more and more force until the connector goes out of the socket.

Pull the cable corresponding to the biggest white connector out of the groove inside the middle frame (long box in the picture below). Then pull up the small ribbon cable (the small box in the lower left part of the picture below).

Now you can lift the middle frame and disconnect the ribbon cable still tying it to the mainboard by gently pulling it upwards (the box at the right in the picture below):

The middle frame is completely removed. Next we will release the mainboard.

Unplug the two white connectors (the two boxes at the left in the photo above).

Then disconnect from the motherboard the 5 ribbon cables marked with green in the photo below. To do so lift the small wide lock going at the top of the socket. This will release the ribbon cable. To release the sixth cable connecting the card reader board first you will need to remove the screw attaching the board to the housing. When you finished detach the ribbon cable as you did to other five ribbon cables. The card reader board cable and its screw are encircled with blue in the picture below.

Disconnect the 2 antenna cables (green in the picture below) by pulling them up off the antenna jacks. Release the light gray one from under the 2 adhesive tape pieces covering it (marked with yellow boxes). Then unscrew the female screw and the black screw (encircled with red).

Remove the 2 screws fixing the fan (green in the picture below). Lift up the phone jack (red) from the chamber in the housing. Now you can lift a bit the mainboard. Then you can detach the ribbon cable (marked with blue) connecting the network I/O board from the mainboard using the same technique you have used for other ribbon cables surrounding the mainboard.

At this point we’ve finished releasing the mainboard. We won’t disconnect it entirely.

Open the laptop’s lid to the maximum. Take a layer of thick cloth or soft packaging material and put it onto the LCD screen to prevent it from scratches. Then turn the mainboard around the wires still connecting it to the housing and lay it down to the screen.

There are 3 silver screws attaching the heatsink to the mainboard. Unscrew them:

Turn the heatsink assembly to the left around the adhesive tape glued to the heatsink exhaust and the fan. (we won’t remove this tape also.) While doing this be careful and apply moderate force as former thermal compounds can take some time to release the heatsink. Overly pulling the heatsink assembly can damage the chips it is attached to. If the heatsink can’t be released by a moderate force than use a hairdryer to make the old compound softer and then you will be able to detach the heatsink assembly from the chips easily.

The following photo shows the heatsink assembly opened. As you can see this side of the assembly covers the two chips.

After the heatsink assembly is opened you can begin cleaning. Vacuum clean the vents and the fan. Also you may use Q-tips to reach inaccessible areas. Clean until no considerable amount of dust left.

What is good for this laptop model is that the CPU has not to be removed from its socket in order to renew thermal compound. This minimizes the risk of damaging CPU’s pins and the CPU socket.

Remove the old pieces of thermal compound from the chips and corresponding heatsink areas. Finish by perfectly cleaning the surfaces with cotton swabs soaked in acetone or 99% alcohol.

Apply sufficient amount of thermal compound on each chip and evenly distribute it over the whole surface:

At this point the heatsink maintenance is over. 

Flip the heatsink assembly back to its place and replace the three heatsink screws. Then repeat the whole disassembly process in the opposite order.
more >>

Sunday, September 12, 2010

Ученые продолжают отвоевывать у природы разгадку тайны происхождения жизни

В химических системах с безразличным равновесием спонтанно возникает эволюция http://elementy.ru/news/431401 more >>

Sunday, August 1, 2010

Солнечная энергия дешевеет - Китай роняет цены

http://www.chaskor.ru/article/solnechnaya_energiya_desheveet_9983 more >>

Friday, June 4, 2010

Что угодно-с? Исчезнуть или стать Хаммером?

Гениальное по простоте идеи и, скорей всего, весьма сложное по схеме реализации оборонное новшество от израильской компании Eltics: камуфляжные панели с изменяемой температурой для дезинформирования IR-сенсоров.

Израиль научился делать танки невидимыми

YoutTube: Eltics "Black Fox" Thermal IR Countermeasure System [ShortVersion] more >>