Search code examples
c++linkerfftw

LNK1104 cannot open file 'libfftw3-3.lib'


I am quite fresh in coding C code, trying to use FFTW from the well-known website http://www.fftw.org/ in my Visual Studio 2019. I followed the tutorial (https://www.youtube.com/watch?v=geYbCA137PU), but an error appeared: LNK1104 cannot open file 'libfftw3-3.lib' How should I solve the problem? I have googled it, but looks like most of the solution not quite suitable to mine. Almost the last step! Please!

#include <iostream>
#include <fftw3.h>
using namespace std;

//macros for real and imaginary parts
#define REAL 0
#define IMAG 1
//length of complex array
#define N 8

/*Computes the 1-D fast Fourier transform*/
void fft(fftw_complex* in, fftw_complex* out)
{
    // creat a DFT plan
    fftw_plan plan = fftw_plan_dft_1d(N, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
    // execute the plan
    fftw_execute(plan);
    // do some cleaning
    fftw_destroy_plan(plan);
    fftw_cleanup();
}

/*Computes the 1-D inverse fast Fourier transform*/
void ifft(fftw_complex* in, fftw_complex* out)
{
    // creat a IDFT plan
    fftw_plan plan = fftw_plan_dft_1d(N, in, out, FFTW_BACKWARD, FFTW_ESTIMATE);
    // execute the plan
    fftw_execute(plan);
    // do some cleaning
    fftw_destroy_plan(plan);
    fftw_cleanup();
    // scale the output to obtain the exact inverse
    for (int i = 0; i < N; ++i) {
        out[i][REAL] /= N;
        out[i][IMAG] /= N;
    }
}

/*Display complex numbers in the form a +/- bi. */
void displayComplex(fftw_complex* y)
{
    for (int i = 0; i < N; ++i)
        if (y[i][IMAG] < 0)
            cout << y[i][REAL] << " - " << abs(y[i][IMAG]) << "i" << endl;
        else
            cout << y[i][REAL] << " + " << y[i][IMAG] << "i" << endl;

}

/*Display real part of complex number*/
void displayReal(fftw_complex* y)
{
    for (int i = 0; i < N; ++i)
        cout << y[i][REAL] << endl;

}

/* Test */
int main()
{
    // input array
    fftw_complex x[N];
    // output array
    fftw_complex y[N];
    // fill the first of some numbers
    for (int i = 0; i < N; ++i) {
        x[i][REAL] = i + 1;  // i.e.{1 2 3 4 5 6 7 8}
        x[i][IMAG] = 0;
    }
    // compute the FFT of x and store the result in y.
    fft(x, y);
    // display the result
    cout << "FFT =" << endl;
    displayComplex(y);
    // compute the IFFT of x and store the result in y.
    ifft(y, x);
    // display the result
    cout << "\nIFFT =" << endl;
    displayReal(x);
}

Solution

  • @HAL9000 Thanks for your reminder. I found out that I have converted the wrong name of .def so I generated a "libfftw3-3l.lib". That's why it couldn't open the file; it has been solved now!