Boost on Ubuntu

Current Ubuntu and Debian distributions lacks up-to-date version of Boost C++ library.

Here is a simple script to install new version with required packages:


# Install packages to Ubuntu (8.04)
sudo apt-get install curl make flex bison libtool automake autoconf
sudo apt-get install g++ python-dev
sudo apt-get install libexpat1-dev libicu-dev libopenmpi-dev libz-dev libbz2-dev
#sudo apt-get install libboost-dev

# Download 1.35+ boost C++ library instead of old (1.34) releases in Ubuntu Linux
curl -O${BOOST_VERSION}_0.tar.bz2
tar xvjpf boost_${BOOST_VERSION}_0.tar.bz2
cd boost_${BOOST_VERSION}_0
echo "using mpi ;" >>user-config.jam
sudo make install
sudo ln -s /usr/local/include/boost-${BOOST_VERSION}/boost /usr/local/include/boost

gprof on OSX Leopard

Step-by-step example to understand usage of gprof on Mac OS X host.

1. Create an example C source, test.c:


int main(void) {
    char some_text[128];
    strcpy(some_text, "1234567890");
    printf("%s\n", some_text);


2. Create Makefile to build universal binary for i386 and PowerPC targets:

# Universal build profile for gprof on Mac OS X by

UNIVERSAL_BUILD = -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -arch i386 -arch ppc
CC = gcc $(CFLAGS)

all: test

test.o: test.c
	$(CC) -c test.c

test: test.o
	$(CC) $(LDFLAGS) -o test test.o

	rm -f *o; rm -f test
    * A universal binary is, in Apple parlance, an executable file or application bundle that runs natively on either PowerPC or x86 (Intel)-based Macintosh computers; it is an implementation of the concept more generally known as a “fat binary”.

3. Build binary with make command:

bash-3.2$ make
gcc -Wall -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -arch i386 -arch ppc -pg -c test.c
gcc -Wall -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -arch i386 -arch ppc -pg -isysroot /Developer/SDKs/MacOSX10.4u.sdk -mmacosx-version-min=10.4 -arch i386 -arch ppc -pg -o test test.o

4. Run test application:

bash-3.2$ ./test 

5. Find generated gmon.out (Your program will write the profile data into a file called “gmon.out” just before exiting. If there is already a file called “gmon.out”, its contents are overwritten. There is currently no way to tell the program to write the profile data under a different name, but you can rename the file afterward if you are concerned that it may be overwritten.):

bash-3.2$ ls -al
total 1376
drwxr-xr-x   7 louise  staff     238 May 11 11:48 .
drwxr-xr-x  21 louise  staff     714 May 11 10:17 ..
-rw-r--r--   1 louise  staff     391 May 11 11:11 Makefile
-rw-r--r--   1 louise  staff  648699 May 11 11:50 gmon.out
-rwxr-xr-x   1 louise  staff   29892 May 11 11:48 test
-rw-r--r--   1 louise  staff     173 May 11 11:08 test.c
-rw-r--r--   1 louise  staff    9104 May 11 11:48 test.o
    * In order to write the `gmon.out’ file properly, your program must exit normally: by returning from main or by calling exit. Calling the low-level function _exit does not write the profile data, and neither does abnormal termination due to an unhandled signal.

6. Start gmon profiler:

bash-3.2$ gprof test gmon.out 
gprof: file: test does not contain the host architecture
    * I don’t know how to avoid this architecture mismatch message, remarks in gmon man page: “UNIVERSAL FILE SUPPORT: gprof accepts a “universal” file for the a.out file, using the host architecture from the file. (It is an error if the “universal” file does not contain the host architecture.)”

7. Display the machine’s architecture type:

bash-3.2$ arch 

8. Take universal header from binary:

bash-3.2$ otool -v -f test
Fat headers
fat_magic FAT_MAGIC
nfat_arch 2
architecture i386
    cputype CPU_TYPE_I386
    cpusubtype CPU_SUBTYPE_I386_ALL
    capabilities 0x0
    offset 4096
    size 13372
    align 2^12 (4096)
architecture ppc
    cputype CPU_TYPE_POWERPC
    capabilities 0x0
    offset 20480
    size 9412
    align 2^12 (4096)

Update: gprof works on OSX Snow Leopard 10.6.1!

granularity: each sample hit covers 4 byte(s) no time propagated

                                  called/total       parents 
index  %time    self descendents  called+self    name    	index
                                  called/total       children

                0.00        0.00       1/1           __start [1856]
[114]    0.0    0.00        0.00       1         _main [114]