November 4, 2010 0

Compile VTK on Snow Leopard

By in OpenFOAM

Compiling VTK on Mac OS X 10.6 turned out to be much harder than on the Unix systems, I’ve done that on recently. Unfortunately I did not find any detailed data on how to choose the installation parameters properly. After a lot of try and error and some research, the following procedure worked for me on 10.6.4.

1. Prerequisities

I should note that I used the latest version of the git repository and not the tarball. The reason for this was that I would like to be able to update the installation more easily in the future.

  • Grab cmake. I used the binary version 2.8.3 and install the command line version as well!
  • Install git for mac.

2. Clone the git repository

The next step is to clone the git repository. Before doing that, I created a parent folder to organize the source and binary files.

mkdir $HOME/Applications/src/VTK
cd $HOME/Applications/src/VTK

In that folder we clone the git repository and checkout the release branch by performing

git clone git://vtk.org/VTK.git VTK
cd VTK
git checkout release

3. Cmake

The cmake configuration differs in some parts from the Unix cmake configuration. Since I’ve several different versions of gcc installed on my machine, I have to link to the one I’d like to use. If no backward compatibility to 10.5 is required, the best CMAKE_OSX_ARCHITECTURES is x86_64 and the usage of i386 caused errors after the compilation finished successfully.

 ccmake ../VTK -G "UNIX Makefiles"        \
	 	-DCMAKE_CXX_COMPILER:PATH=/usr/bin/c++-4.2 \
		-DCMAKE_C_COMPILER:PATH=/usr/bin/gcc-4.2 \
		-DVTK_USE_QVTK:BOOL=ON            \
		-DVTK_USE_COCOA:BOOL=ON          \
		-DVTK_USE_CARBON:BOOL=OFF          \
		-DCMAKE_BUILD_TYPE:STRING=Release \
		-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64 \
		-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.6 \
		-DBUILD_SHARED_LIBS:BOOL=ON \
		-DPYTHON_EXECUTABLE:PATH=/usr/bin/python \
		-DCMAKE_INSTALL_PREFIX:PATH= \
		-DVTK_WRAP_PYTHON:BOOL=ON \
		-DVTK_USE_GUISUPPORT:BOOL=ON

After building the makefiles using this cmake configuration, I had to create a symbolic link to my python site-packages. The installation pointed to a wrong directory and I didn’t figure out which parameter I had to set to avoid this. Therefore:

sudo mkdir /lib/python2.6
sudo ln -s /Library/Python/2.6/site-packages /lib/python2.6/site-packages

Now I just compiled on 4 cores

make -j 4
sudo make install

4. Postinstallation

After the installation, some environmental variables in my $HOME/.bash_profile:

export LD_LIBRARY_PATH=/lib/vtk-5.6:$LD_LIBRARY_PATH
export PYTHONPATH=/Library/Python/2.6/site-packages:$PYTHONPATH
export DYLD_LIBRARY_PATH=/lib/vtk-5.6:$DYLD_LIBRARY_PATH

Done! Now python 2.6 runs with VTK.

Tags: , , ,

Leave a Reply