Browse > Home / Computer, How To, Science / Blog article: Installing VTK on Mac OS X

Installing VTK on Mac OS X

September 6th, 2009 Posted in Computer, How To, Science

VTK Precompiled Universal Binaries

The comet program uses VTK for all its 3D rendering—if you want to compile comet with 3D output, you’ll need to link against the VTK libraries.  I describe below how I built them, but if you simply want to use them, you can download Universal Binaries of the VTK libraries for OS X here (The current version is 5.5 as of 09/06/09).  The libraries are in the file called ‘VTK5.5universal.zip’, and you can find the the source tree from which they were compiled in ‘VTKBuild.zip’.

To use these for an XCode project, open the project, select Project->Edit Project Settings and under the Build tab change ‘Library Search Paths’ to include the path to the libraries, e.g., /Users/mark/VTK/lib/ and ‘Header Search Paths’ to include the path to the header files, e.g., /Users/mark/VTK/include/ (changing the user name and version as appropriate).

Building VTK as Universal Binaries on OS X

It took me a little while to get VTK compiled on OS X 10.5, so I’m posting the instructions here in case they are helpful to others trying to compile it.  VTK uses cmake, which is not very straightforward, but seems robust once you know the secret ways.  This is largely based on the vtk wiki, the instructions here and some fiddling. Note: this is using the CVS version version of VTK (currently 5.5)

First, install the Apple Developer Tools (Xcode), and Macports, then open a terminal and use Macports to install CMake:

sudo port selfupdate
sudo port install cmake

Create a directory for VTK, and download the CVS version of the software:

mkdir VTK
cd VTK
cvs -d :pserver:anonymous@public.kitware.com:/cvsroot/VTK login

enter ‘vtk’ as the password, then start the download:

cvs -d :pserver:anonymous@public.kitware.com:/cvsroot/VTK checkout VTK

Make a directory for the build and run cmake from that directory, pointing to the source you just downloaded:

mkdir VTKBuild
cd VTKBuild
cmake ../VTK

Cmake will make its config files based on the system info. These will be almost right, but we need to open CMakeCache.txt in a text editor and change the following (replace /Users/mark/VTK/VTKBuild with the path you chose above):

CMAKE_BUILD_TYPE:STRING=Release
CMAKE_EXE_LINKER_FLAGS:STRING=-Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib
CMAKE_INSTALL_PREFIX:PATH=/Users/mark/VTK/VTKBuild

Make sure to change the username in that last line to match your own. If you want to make universal binaries, edit these lines including the targets you want:

CMAKE_OSX_ARCHITECTURES:STRING=ppc;ppc64;i386;x86_64
CMAKE_OSX_SYSROOT:PATH=/Developer/SDKs/MacOSX10.5.sdk

Then call cmake again and it will write out a makefile:

cmake ../VTK

Finally, compile and install (this takes some time):

make
make install

If all is well, you should have a set of compiled libraries in VTKBuild/bin and include files in VTKBuild/include/vtk-5.5 (depending on the current VTK version number).  If you built universal binaries, you can check the architectures by using lipo:

$ lipo -info libvtkRendering.a
Architectures in the fat file: libvtkRendering.a are: ppc ppc64 i386 x86_64
Share:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Slashdot
  • StumbleUpon
  • LinkedIn
  • Twitter
  • FriendFeed

Related posts:

  1. Building GSL as a Universal Binary Here's a universal binary of the Gnu Scientific library (GSL) for OS X, including the ppc, ppc64, i386 and x86_64...
  2. Setting bash variables from an XML file Here's a quick way to set bash variables using data from an XML file...

Tags: ,

Leave a Reply

*
To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
Click to hear an audio file of the anti-spam word