EN ·
🌏 中文

Configuring FFTW 3.3.2 in Visual Studio 2010

0. Introduction

When developing signal processing or image processing applications, a high-performance Fast Fourier Transform (FFT) library is essential. FFTW is widely considered the leading open-source implementation for this task. While there are various guides online, many are incomplete or scattered. This article provides a consolidated guide for configuring FFTW 3.3.2 in a Visual Studio 2010 (VS2010) environment.

Conventions:


1. Core Concepts

1.1 FFTW 3.3.2

FFTW (Fastest Fourier Transform in the West) is a comprehensive C library for computing the Discrete Fourier Transform (DFT), developed at MIT by Matteo Frigo and Steven G. Johnson. It supports multi-dimensional DFTs, real and complex data, and arbitrary input sizes. FFTW is highly optimized and automatically adapts its performance to your specific hardware (cache, memory, registers).

1.2 VS2010

The Microsoft Visual Studio 2010 Integrated Development Environment.


2. Setup Guide

2.1 Download

  1. Visit the FFTW Windows Installation page and download the latest pre-compiled DLLs (e.g., the 32-bit version).
  2. Extract the contents to Path 1.

2.2 Generate .lib Files

Open the command prompt (cmd), navigate to Path 1, and execute the following three commands:

lib /machine:ix86 /def:libfftw3-3.def
lib /machine:ix86 /def:libfftw3f-3.def 
lib /machine:ix86 /def:libfftw3l-3.def 

Note: The last command uses 3l (lowercase L).

Upon success, three .lib files will be generated in Path 1. Your folder should now contain three .dll files, three .lib files, and the fftw3.h header.

2.3 Troubleshooting

Problem 1: lib command not found

Problem 2: Missing DLLs for lib.exe

2.4 Configure VS2010 Project Properties

  1. Launch VS2010 and create a new Win32 Console Empty Project.
  2. Press Alt + F7 to open the Project Properties.
  3. Navigate to Configuration Properties -> VC++ Directories:
    • Add Path 1 to Include Directories.
    • Add Path 1 to Library Directories.
  4. Navigate to Configuration Properties -> Linker -> Input:
    • In Additional Dependencies, add the following:
    libfftw3-3.lib
    libfftw3f-3.lib
    libfftw3l-3.lib

The environment is now ready.


3. Testing the Configuration

Add a new file main.cpp to the Source Files of your project and paste the following test code:

#include "fftw3.h"
#include <stdio.h>
#define N 8

int main()
{
	int i;

	fftw_complex *in, *out;
	fftw_plan p;
	in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
	out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);

	if((in == NULL) || (out == NULL))
	{
		printf("Error: insufficient available memory\n");
	}
	else
	{
		for(i = 0; i < N; i++) /* Prepare test data */
		{
			in[i][0] = i + 1;
			in[i][1] = 0;
		}
	}

	p = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);

	fftw_execute(p); /* Execute the transform */
	fftw_destroy_plan(p);
	fftw_cleanup();

	printf("Input Data:\n");
	for(i = 0; i < N; i++)
	{
		printf("%f, %fi\n", in[i][0], in[i][1]);
	}

	printf("\nOutput (FFT Result):\n");
	for(i = 0; i < N; i++)
	{
		printf("%f, %fi\n", out[i][0], out[i][1]);
	}

	if(in != NULL) fftw_free(in);
	if(out != NULL) fftw_free(out);
	
	getchar();
	return 0;
}

Expected Output

If correctly configured, the program will output the original sequence followed by its FFT result:

1.000000,0.000000i
2.000000,0.000000i
3.000000,0.000000i
4.000000,0.000000i
5.000000,0.000000i
6.000000,0.000000i
7.000000,0.000000i
8.000000,0.000000i

36.000000,0.000000i
-4.000000,9.656854i
-4.000000,4.000000i
-4.000000,1.656854i
-4.000000,0.000000i
-4.000000,-1.656854i
-4.000000,-4.000000i
-4.000000,-9.656854i

Setup complete.