Conditional compilation of resource file for different icons in visual studio C++

Combining the instruction from the post here and a blog here, I summarize the steps to dynamically use different icons in resource script file (.rc file).

1. Open your project in Visual Studio 2010
2. Right click on resource script file (e.g. app.rc) and select “Properties”
3. At the top of the property page, select one product solution configuration like “Product A” or “Product B”. This is similar to “Win32”, or “x64”, but for different product.
4. In the left menu bar, select [Configuration Properties] / [Resources] / [General].
5. In the “Preprocessor Definitions” field, add “Product_A” for “Product A” configuration and “Product_B” for “Product B” configuration . The field value will become “NDEBUG;%(PreprocessorDefinitions);Product_A”.
6. Click OK to close the window.
7. Right click on resource script file (e.g. app.rc) and select “View Code”.
8. In the code editor, add #ifdef and #elif to conditionally include resources when compiling. Use “Product_A” and “Product_B” preprocessor definitions that we defined just now.

Here is a sample code:

#ifdef Product_A
	IDI_MAINFRAME_ICON  ICON  "..\\Software\\res\\idr_main_A.ico"
#elif Product_B
	IDI_MAINFRAME_ICON  ICON  "..\\Software\\res\\idr_main_B.ico"
	IDI_MAINFRAME_ICON  ICON  "..\\Software\\res\\idr_main.ico"

9. Save the resource script file and compile the project in different platforms.

nafxcwd.lib(afxglobals.obj) : error LNK2001: unresolved external symbol _IID_IWICImagingFactory

My setting:
VC2010 SP1 on Windows 7 64bit
Without any modification of the environmental variables or upgrading VC2010, I hit this error upon rebuild of an old project

nafxcwd.lib(afxglobals.obj) : error LNK2001: unresolved external symbol _IID_IWICImagingFactory

My solution:
1. At project->Properties->Configuration Properties->Linker->Input->Additional Dependencies I added windowscodecs.lib. This is a library under

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib

If you don’t have it, install Windows SDKs

2. Compile the project still hit some errors and recompile builds the project successfully

For details of discussion on this issue see here

Allow OpenVPN access LAN/Intranet behind the server (Ubuntu 14.04)

The default setting of openvpn only allows client to visit the openvpn server only. To allow the client to visit the LAN behind the server you need to forward the package from tun0 (the vpn) to wlan0 (the internet your server is using). For those who are using other interface to access internet, choose ech0, ech1, etc. accordingly.

/sbin/iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
/sbin/iptables -A FORWARD -i wlan0 -o tun0 -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i tun0 -o wlan0 -j ACCEPT

Install h5py on Ubuntu 12.04

I used the following commands:

$ wget
$ tar -xzf h5py-2.2.0.tar.gz
$ cd h5py-2.2.0
$ export C_INCLUDE_PATH=/usr/lib/openmpi/include

If you don’t issue the last command, you will see errors like “mpi.h” cannot be found

$ python build
$ python test
$ sudo python install

By now, you have h5py installed. Try this example:, and observe a beautiful picture generated using all processors on your computer.



Qt5, Windows 7, MSVC 2010, and 64 bit compilation

Basically following this blog. However not every step works for me so some steps are modified. Local downloads of python, ICU, Perl64, ruby, openSSL and Windows SDK are offered.

1-Download and install python

2-download and unzib ICU to c:icu

3-Download and install Perl64

4-Download and install ruby

5-Download and install OpenSSL

6-Download and install Windows SDK

7-Download and unzib QT5 source to a any directory, ex D:Qt64Qt5.1.1qtbase
(This path will be added to path variable in your environment variables later)

8-Download jom

9-Make a new environment variable
Value: win32-msvc2010

10-Make another environment variable
Value: D:Qt64Qt5.1.1qtbase

11-Make sure you have these vars in your path

12-After installing everything, start “Visual Studio x64 Win64 Command Prompt” from start menu

13-Enter these commands

set CL=/MP
cd D:Qt64Qt5.1.1qtbase

configure -debug-and-release -confirm-license -opensource -mp -qt-sql-sqlite -opengl desktop -platform win32-msvc2010 -openssl -L C:/OpenSSL-Win64/lib -I C:/OpenSSL-Win64/include

This configure command is different from the qt blog.

14-Now the configuration process starts, it will take around a minute to configure qt

15-After the configuration finishes just type nmake or jom.exe -j6. I have 8 threads so I used 6

16-The compiling should start, this took 3.5~4 hours on my Intel i7 2670.

17-type nmake doc or jom.exe -j6 doc to generate the documentation. After building, you should find *qch files under D:Qt64Qt5.1.1qtbasedoc

If you need to compile QtCreator X64 you need to

1-Download and unzib QtCreator source code to a directory ex D:Qt64qt-creator-5.1.1

2-Start “Visual Studio x64 Win64 Command Prompt” from start menu

3-Enter these commands

set CL=/MP
cd D:Qt64qt-creator-5.1.1

D:Qt64Qt5.1.1qtbasebinqmake.exe -r -spec win32-msvc2010 "CONFIG+=release" "QT_PRIVATE_HEADERS=D:Qt64Qt5.1.1qtbaselib"

The above command is different from the qt blog.

4-After the processing finishes just type nmake or jom.exe -j6 and PRESS ENTER
this will take around 1 hour to complete.


After Qtcreator built, changing a user local path, restart, or installation of any qt plugin may make qtcreator not working. For example, I got messages like “QT5core.dll” not found, even though I can use Qtcreator after building. So

5- copy all *.dll from D:Qt64Qt5.1.1qtbasebin to D:Qt64qt-creator-5.1.1bin

if you want to compile mysqldriver plugin

1-Download and install MySql Server

2-Go to D:Qt64Qt5.1.1qtbasesrcpluginssqldriversmysql and open the file “”
in notepad

3-Add the following lines at the end of the file
INCLUDEPATH += “C:Program FilesMySQLMySQL Server 5.5include”
LIBS += -L“C:Program FilesMySQLMySQL Server 5.5lib”

4- save and close the file

5-Start “Visual Studio x64 Win64 Command Prompt” from start menu

6-Enter these commands
cd D:Qt64Qt5.1.1qtbasesrcpluginssqldriversmysql PRESS ENTER



7- Now just type nmake PRESS ENTER
The mysql driver plugin should now be compiled

D-Link DWA-125 works on ubuntu 12.04 server out of the box

Just to confirm. Set up step is easy, once you plug in the usb adapter.

Step 1. use

$ ifconfig

to find out if wlan0 is already up. If not,

$ sudo ifconfig wlan0 up

Step 2. Check if the adapter detects available wifi signals

sudo iwlist scan

It works on my ubuntu 12.04.

Step 3. the WIFI spot I am about to connect is password protected. So need to type


This will result in something that looks like this:

psk=fe727aa8b64ac9b3f54c72432da14faed933ea511ecab1 5bbc6c52e7522f709a

Remember the long string.

Step 4. Next, you need to edit your interfaces file, so issue:

sudo nano /etc/network/interfaces

At the end of this file, you need to add your WiFi configuration. Here are the options you can add.

auto wlan0     #change this to the name of your WiFi interface
iface wlan0 inet dhcp     #this is normally fine, if you want a static IP address replace “dhcp” with “static”
netmask     #change this as appropriate for your network, this value is usually right
gateway     #change this as appropriate for your network
address     #only needed for a static IP address
dns-nameservers     #only needed for a static IP address
wpa-driver wext     #you shouldn’t need to change this
wpa-ssid YOURSSID     #just type the name of your SSID here
wpa-ap-scan 1     #if the name of your SSID is hidden usually, type 2 instead of 1
wpa-proto WPA    #if you use WPA1 type WPA, if you use WPA2 type RSN
wpa-pairwise CCMP     #if you use AES type CCMP, if you use TKIP type TKIP
wpa-group CCMP     #if you use AES type CCMP, if you use TKIP type TKIP
wpa-key-mgmt WPA-PSK     #usually WPA-PSK (if you share a key) but sometimes WPA-EAP (for enterprises)
wpa-psk YOURHEXKEYFROMABOVE     #the hex key that you generated earlier

Step 5. Finally, comment out the top section so it looks like this:

#auto eth0
#iface eth0 inet dhcp

This stops your wired network from working. This helps to ensure there are no conflicts. Remember, if you want your wired network to work again, remove these two comments (the #).

After the 5 steps, my usb adapter is up and running. You can reboot if needed to reconfigure the networking interface.

A major part of this learning notes follow this blog.

set up your own git repository with Qtcreator on Ubuntu 12.04 server

I followed this instruction
Since I am the only developer, I simplified the process a lot. Here are the steps:
1. make sure git has been installed by checking

$ which git

or install it by typing:

$ sudo apt-get install git-core

2. create your git folder on ubuntu server 12.04

$ cd
$ mkdir git
$ cd git
$ mkdir project1.git
$ cd project1.git
$ git --bare init

3. on the local computer where you develop programs, type

# on local computer
$ cd myproject
$ git init
$ git add .
$ git commit -m 'initial commit'
$ git remote add origin
$ git push origin master

4. on the local computer I develop programs in Qtcreator. After the above steps, git remote repository is already set and thus future operations can be committed to the remote server.

git under Qtcreator

git under Qtcreator

When a 6-node cluster told you this “connect() to failed: Connection refused (111)”

and all processors hangs, like waiting for ever. Here is the solution and I just do a copy/paste:

Tell Open MPI not to use the virtual bridge interface virbr0 interface for sending messages over TCP/IP. Or better tell it to only use eth0 for the purpose:

$ mpiexec --mca btl_tcp_if_include eth0 ...

This comes from the greedy behaviour of Open MPI’s tcp BTL component that transmits messages using TCP/IP. It tries to use all of the available network interfaces that are up on each node in order to maximise the data bandwidth. Both nodes have virbr0 configured with the same subnet address. Open MPI falls to recognise that both addresses are equal, but since the subnets match, it assumes that it should be able to talk over virbr0. So process A is trying to send a message to process B, which resides on the other node. Process B listens on port P and process A knows this, so it tries to connect to But this is actually the address given to the virbr0 interface on the node where process A is, so the node tries to talk to itself on a non-existent port, hence the “connection refused” error.

To avoid remember such a long command, I added

alias mympirun='mpirun --mca btl_tcp_if_include eth0'

to ~/.bashrc

Use ganglia to monitor DRBL (Diskless Remote Boot in Linux) based cluster

Another helmer cluster with 52 cores, 104 GB RAM and 3 TB hard disk has been assembled. To monitor master and slave nodes, I installed ganglia on the master node. In a nutshell, ganglia works like this:
1. gmond: A process running on the slave nodes. On Ubuntu, run

sudo apt-get install ganglia-monitor

to install it. It’s configuration file is /etc/gmond.conf, and the associated service is ganglia-monitor.
2. gmetad: A process running on the master that collects the statistics sent by the various gmond processes in the slave nodes. For Ubuntu, this is the package ganglia-webfrontend package:

sudo apt-get install ganglia-webfrontend

Its configuration in /etc/gmetad.conf, and the associated service is gmetad.
3. A web UI: The web front end is installed/contained within the same package as gmetad. The UI is used to display the collected data.

Since the DRBL based slave nodes have no harddrive, so all the services must be started from the master.
1. The first step is to add “#mcast_if = eth1”:

/* Feel free to specify as many udp_send_channels as you like.  Gmond
   used to only support having a single channel */
udp_send_channel {
  mcast_join =
  #mcast_if = eth1
  port = 8649
  ttl = 1

/* You can specify as many udp_recv_channels as you like as well. */
udp_recv_channel {
  mcast_join =
  #mcast_if = eth1
  port = 8649
  bind =

The master node uses eth1 to communicate with slaves, whereas slaves use eth0 communicate with the master. So the trick here is keep the “#” and do

sudo drblpush -c /etc/drbl/drblpush.conf

2. With all slaves alive, run the following commands

sudo drbl-client-service ganglia-monitor on
sudo drbl-doit "/etc/init.d/ganglia-monitor start"

3. done. It will look like this

Ganglia monitor DRBL based cluster

Ganglia monitor DRBL based cluster

!!!Remember before every time you run

sudo drblpush -c /etc/drbl/drblpush.conf

Keep the “#” in front of “mcast_if = eth1” and uncomment it when you start ganglia on the master node.