Compiling the NFFT library for 64-bit Windows and Matlab. (Updated November 2013)

Update (Feb 2014) : If you don’t want to go through the steps below, why not try these pre-compiled binaries. Just unzip them to somewhere inside your MATLAB path. (These binaries are compiled with the header files from MATLAB 2013a, so your results may vary if you use a different MATLAB version).

A few people commented recently that they were unable to compile the NFFT library for 64-bit Windows and Matlab, following my previous instructions. It has been a while since I’ve actually used these libraries on windows, so I wanted to see if my instructions were still valid. Here are the results of my attempts, with the latest versions I could find.

Step 1:

You need a suitable compilation environment.  I wanted native 64 bit binaries, so my only real choice was to use the 64 bit mingw-32 compiler.  I chose to use the 64-bit cygwin environment to ease the setup of this compiler.  Download the cygwin setup-x86_64.exe from the cygwin homepage.

Run the setup.exe file and when you come to select packages, check at least make and mingw64-x86_64-gcc-core under the devel section.

Step 2:

Open the cygwin terminal.  Now we need to obtain the fftw3 library.  The FFTW project provides precompied windows binaries, and the best choice here is to use these.  Go to the FFTW windows download page, and select the download link for the 64 bit binaries.

As we are using cygwin and have a terminal open I ran

$ wget ftp://ftp.fftw.org/pub/fftw/fftw-3.3.3-dll64.zip

to download the zip file into my cygwin home directory, and

$ unzip -d fftw-3.3.3 fftw-3.3.3-dll64.zip

to unzip it into a subdirectory.

The final stage is to rename the fftw dll so that it can be found and properly linked.  Simply change into your fftw directory and rename or copy libfftw3-3.dll to libfftw3.dll

$ cd fftw-3.3.3
cp libfftw3-3.dll libfftw3.dll
cd ..

Step 3:

Obtain the NFFT source code.  The latest version as of November 2013 is 3.2.3 and is available from the NFFT download page.

I ran the following to download and unzip the source:

$ wget http://www-user.tu-chemnitz.de/~potts/nfft/download/nfft-3.2.3.tar.gz
tar zxvf nfft-3.2.3.tar.gz

Now cd into nfft-3.2.3 and configure the build.  The options I chose worked well for me, and they assume that your matlab installation is located in C:\MATLAB\R2013a, this needs to be changed for different releases and installation locations (nb. if your matlab folder is of the form C:\Program Files\MATLAB\R2013a, then the space in the path may cause problems, you can try making a windows symlink between C:\Program Files\MATLAB and C:\MATLAB, to do this open an elevated command prompt, i.e. Start Menu, Type ‘cmd’ and then right click on cmd.exe and Run as administrator. Then run ‘mklink /D C:\MATLAB”C:\Program Files\MATLAB”‘)

So I ran the following command in the cygwin terminal: (replace jpowell with your username, I didn’t use ~/ style as this seemed to cause problems when building)

$ cd nfft-3.2.3
export LIBS=-lws2_32
 ./configure --host=x86_64-w64-mingw32 --enable-all --enable-openmp --with-fftw3-libdir=/cygdrive/c/Users/jpowell/fftw-3.3.3/ --with-fftw3-includedir=/cygdrive/c/Users/jpowell/fftw-3.3.3/ --with-matlab=/cygdrive/c/MATLAB/R2013a/ --with-matlab-arch=win64 --with-matlab-fftw3-libdir=/cygdrive/c/Users/jpowell/fftw-3.3.3/

The critical command here is –host=x86_64-w64-mingw32 this configures the compilation for a mingw-w64 cross compile, and produces binaries that are not linked to cygwin.  If the configure script runs without errors you can type

$ make

to compile.

Step 4:

The final step for me was to get the compiled binaries working in my Matlab environment.  For me this involved copying the nfft helper functions in C:\Users\jpowell\nfft-3.2.3\matlab\nfft into a subdirectory in my matlab folder.  To simplify things I copied the libnfft.mexw64 file from C:\Users\jpowell\nfft-3.2.3\matlab\nfft\.libs into the same directory as the helper functions and then renamed it to nfftmex.mexw64.

This nfftmex binary relies on a couple of other dynamic libraries, including libfftw3-3.dll so I copied that into the same directory from C:\Users\jpowell\fftw-3.3.3.  I also need some additional mingw libraries, libgomp-1.dll, libgcc_s_seh-1.dll and libwinpthread-1.dll, which can be found in your cygwin install at C:\cygwin64\usr\x86_64-w64-mingw32\sys-root\mingw\bin

If you still have other dependancies causing Matlab to not recognise the mex file as valid, you can try using Dependancy Walker to see track these down.

With all of those installed I can confirm everything is working by running the matlab command nfft_get_num_threads to show that the nfft library is working and taking advantage of all the available threads of my processor.

Let me know if this helps, or if you encounter any problems following the above instructions.  Hopefully the changes to make for a 32 bit system or different version of matlab will be easy enough to work out.

3 thoughts on “Compiling the NFFT library for 64-bit Windows and Matlab. (Updated November 2013)”

  1. Hello,
    I succeded in the different steps except the last one. When I run the simple_test.m provided with NFFT, it says the the specified module cannot be found… The only thing I was unsure is the step with the helper function. Could you specify explicitely where it should be copied? I feel like I’m alost there!!
    Thanks

Leave a Reply