AudioPlastic

Installing FFTW Using Homebrew on OSX When You Want to Statically Link a Matlab Mex File

| Comments

I’ve been playing with implementing and benchmarking various FFT implementations as Matlab mex files under OSX. I use the excellent homebrew as my package management system. I wanted to compare the vDSP FFT routines from the Apple Accelerate framework against FFTW. Installing FFTW is as simple as typing brew install fftw from the command line. However, when linking fftw against the mex file, the mex compiler tool in Matlab will always want to dynamically link the library (think version problems and other P.I.T.A.). Now it is possible to add -static to your linker flags in the mexopts.sh file (found in ~/.your_matlab_version/mexopts.sh), but then this will then break the build if you try to include the Accelerate framework simultaneously (see previous post). Hmmmm.

Luckily, it is super easy to edit a brew formula. From the terminal, just type brew edit fftw. This brings up the formula details. From here it is possible to remove all of the dynamic linking options by just removing the flags in the args variable, so your formula ends up looking like this …

fftw formula
1
2
3
4
5
6
7
8
9
10
11
12
13
14
require 'formula'

class Fftw < Formula
  homepage 'http://www.fftw.org'
  url 'http://www.fftw.org/fftw-3.3.3.tar.gz'
  sha1 '11487180928d05746d431ebe7a176b52fe205cf9'

  option "with-fortran", "Enable Fortran bindings"

  depends_on :fortran => :optional

  def install
    args = []
	...

After removing and reinstalling fftw, matlab will automatically statically link it against the mex file. Perhaps not the most elegant solution, but a simple solution nonetheless.

Comments