Compiling the NFFT library for 64-bit Windows and Matlab.

So I use the NFFT library for work on a 64 bit Ubuntu Linux machine, where it is relatively easy to compile and set up.  All the dependencies are in the linux repositories, and compiling is simple and straightforward.  However I wanted to be able to run my matlab code and test scripts on my home machine, running Windows 7 64 bit without dual booting OSes or running a painfully slow VM.

It was a bit of a pain, but I finally succeeded in getting some working binaries up and running.  Maybe this will save someone else some time and pain.

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 cygwin environment to ease the setup of this compiler.  Download the cygwin setup.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.2-dll64.zip

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

$ unzip -d fftw-3.3.2 fftw-3.3.2-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.2
cp libfftw3-3.dll libfftw3.dll
cd ..

Step 3:

Obtain the NFFT source code.  The latest version as of July 2012 is 3.2.0 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.0.tar.gz
tar zxvf nfft-3.2.0.tar.gz

Now cd into nfft-3.2.0 and configure the build.  The options I chose worked well for me, and they assume that your matlab installation is located in C:\matlab\R2012a, this needs to be changed for different releases and installation locations (nb. My matlab directory was actually C:\Program Files\MATLAB\R2012a, but this caused problems for the nfft build, so I made 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.0
./configure --host=x86_64-w64-mingw32 --enable-all -enable-openmp --with-fftw3-libdir=/home/jpowell/fftw-3.3.2/ --with-fftw3-includedir=/home/jpowell/fftw-3.3.2/ --with-matlab=/cygdrive/c/matlab/R2012a/ --with-matlab-arch=win64 --with-matlab-fftw3-libdir=/home/jpowell/fftw-3.3.2/

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:\cygwin\home\jpowell\nfft-3.2.0\matlab\nfft into a subdirectory in my matlab folder.  To simplify things I copied the libnfft.mexw64 file from C:\cygwin\home\jpowell\nfft-3.2.0\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:\cygwin\home\jpowell\fftw-3.3.2.  I also need some additional mingw libraries, libgomp-1.dll and pthreadGC2.dll, which can be found in your cygwin install at C:\cygwin\usr\x86_64-w64-mingw32\sys-root\mingw\bin

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.

5 thoughts on “Compiling the NFFT library for 64-bit Windows and Matlab.”

  1. Hello I have tried to recompile the library using your instructions but obtained the error messages:

    ../../.libs/libnfft3_matlab.a(libfpt_threads_la-fpt.o):fpt.c:(.text+0x5cd): undefined reference to `__imp_fftw_plan_many_r2r’
    ../../.libs/libnfft3_matlab.a(libfpt_threads_la-fpt.o):fpt.c:(.text+0x75e): undefined reference to `__imp_fftw_plan_many_r2r’
    ../../.libs/libnfft3_matlab.a(libfpt_threads_la-fpt.o):fpt.c:(.text+0x2be9): undefined reference to `__imp_fftw_execute_r2r’
    ../../.libs/libnfft3_matlab.a(libfpt_threads_la-fpt.o):fpt.c:(.text+0x32c6): undefined reference to `__imp_fftw_execute_r2r’
    ../../.libs/libnfft3_matlab.a(libfpt_threads_la-fpt.o):fpt.c:(.text+0x32e2): undefined reference to `__imp_fftw_execute_r2r’
    ../../.libs/libnfft3_matlab.a(libfpt_threads_la-fpt.o):fpt.c:(.text+0x379f): undefined reference to `__imp_fftw_execute_r2r’
    ../../.libs/libnfft3_matlab.a(libfpt_threads_la-fpt.o):fpt.c:(.text+0x37d7): undefined reference to `__imp_fftw_execute_r2r’
    ../../.libs/libnfft3_matlab.a(libfpt_threads_la-fpt.o):fpt.c:(.text+0x3af3): more undefined references to `__imp_fftw_execute_r2r’ follow
    ../../.libs/libnfft3_matlab.a(libfpt_threads_la-fpt.o):fpt.c:(.text+0x72b4): undefined reference to `__imp_fftw_plan_many_r2r’
    ../../.libs/libnfft3_matlab.a(libfpt_threads_la-fpt.o):fpt.c:(.text+0x77dc): undefined reference to `__imp_fftw_execute_r2r’
    ../../.libs/libnfft3_matlab.a(libfpt_threads_la-fpt.o):fpt.c:(.text+0x7a28): undefined reference to `__imp_fftw_plan_many_r2r’
    ../../.libs/libnfft3_matlab.a(libfpt_threads_la-fpt.o):fpt.c:(.text+0x7a47): undefined reference to `__imp_fftw_execute_r2r’
    ../../.libs/libnfft3_matlab.a(libfpt_threads_la-fpt.o):fpt.c:(.text+0x7fae): undefined reference to `__imp_fftw_execute_r2r’
    ../../.libs/libnfft3_matlab.a(libfpt_threads_la-fpt.o):fpt.c:(.text+0x7fd2): undefined reference to `__imp_fftw_execute_r2r’
    ../../.libs/libnfft3_matlab.a(libfpt_threads_la-fpt.o):fpt.c:(.text+0x844b): undefined reference to `__imp_fftw_execute_r2r’
    ../../.libs/libnfft3_matlab.a(libfpt_threads_la-fpt.o):fpt.c:(.text+0x846c): undefined reference to `__imp_fftw_execute_r2r’
    ../../.libs/libnfft3_matlab.a(libfpt_threads_la-fpt.o):fpt.c:(.text+0x87d3): more undefined references to `__imp_fftw_execute_r2r’ follow
    ../../.libs/libnfft3_matlab.a(libnfft_threads_la-nfft.o):nfft.c:(.text+0x61b): undefined reference to `__imp_fftw_plan_dft’
    ../../.libs/libnfft3_matlab.a(malloc.o):malloc.c:(.text+0x2e): undefined reference to `__imp_fftw_malloc’
    ../../.libs/libnfft3_matlab.a(nfct.o):nfct.c:(.text+0x4009): undefined reference to `__imp_fftw_plan_r2r’
    ../../.libs/libnfft3_matlab.a(nfct.o):nfct.c:(.text+0x47d9): undefined reference to `__imp_fftw_plan_r2r’
    ../../.libs/libnfft3_matlab.a(nfct.o):nfct.c:(.text+0x4ec9): undefined reference to `__imp_fftw_plan_r2r’
    ../../.libs/libnfft3_matlab.a(nfct.o):nfct.c:(.text+0x5589): undefined reference to `__imp_fftw_plan_r2r’
    ../../.libs/libnfft3_matlab.a(nfct.o):nfct.c:(.text+0x5c79): undefined reference to `__imp_fftw_plan_r2r’
    ../../.libs/libnfft3_matlab.a(nfst.o):nfst.c:(.text+0x3da5): more undefined references to `__imp_fftw_plan_r2r’ follow

    any help would be appreciated…

    1. Hi,

      It looks like the linker is not able to find the FFTW library.

      Did you make sure to change the references to “jpowell” in the following step to whatever equivalent username you are using?

      ./configure –host=x86_64-w64-mingw32 –enable-all -enable-openmp –with-fftw3-libdir=/home/jpowell/fftw-3.3.2/ –with-fftw3-includedir=/home/jpowell/fftw-3.3.2/ –with-matlab=/cygdrive/c/matlab/R2012a/ –with-matlab-arch=win64 –with-matlab-fftw3-libdir=/home/jpowell/fftw-3.3.2/

      I would expect the ./configure stage to fail though if you hadn’t setup the path to the libraries correctly.

      I might be able to help further if you provide the full log of whichever command is failing, possibly by piping the output into a text file and either attaching it here, or emailing it to me at jpowell@jpowell.co.uk

    2. I haven’t actually used these libraries on Windows in a while, so I tried to repeat my instructions with the most recent libraries available. I posted an updated set of instructions here http://jpowell.co.uk/?p=77, do you want to try following those and see if you still get the same errors?

  2. Hi,

    I get the same error messages (see below) as posted by fdoperez and I was wondering if you have ever figured out the problem. The ./configure stage seems to find the path to the fftw library. Any help would be much appreciated.

    Thank you for taking the time to post this step-by-step tutorial. I hope I can get it to work!

    Jerome


    ../../.libs/libnfft3_matlab.a(fpt.o):fpt.c:(.text+0x661): undefined reference to `fftw_plan_many_r2r’
    ../../.libs/libnfft3_matlab.a(fpt.o):fpt.c:(.text+0x661): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `fftw_plan_many_r2r’

  3. Thanks so much for this. I’ve been waiting for a Mac at my work and been using W7 in the mean time. I’ll be using the PyNFFT wrapper instead of MATLAB. I hope I have success…I’ve used this lib before and it is really cool and I have a use for it asap….cheers !

Leave a Reply